IOS write IOS image to SQLITE BLOB

To transfer a IOS SQLITE BLOB from a SQLITE database to an IOSImage is easy. I have found the example in EEIOS app:

Dim photo as IOSImage
photo = iOSImage.FromData(projetRS.Field(“myphoto”).NativeValue)

But, to do the opposite way, I’ve got no method to return it to a BLOB and write it to my IOS SQLITE database.

Thanks for help.

iOSImage.ToData will convert an image to binary data, which you can then send along to the DB.

I ended up using a Declare because ToData was losing orientation information. I will look in my app later this evening and post up what I ended up doing.

Created a method that I passed the Image and returned it as a MemoryBlock:

	[code]Declare function UIImageJPEGRepresentation lib UIKitLib (obj_id as ptr) as ptr
	dim d as new Foundation.NSData(UIImageJPEGRepresentation(image.Handle))
	dim mb as MemoryBlock
	mb = d.DataMb
	return mb

I called it ToDataMB.

Here is how I called it.

[code] imgMb=ToDataMB(img)

	If imgMb.Size=0 Then
			MsgBox "MemoryBlock is Blank!"
	End If

I converted it to Base64 encoded Text and thats how I stored it.

Thanks goes to Jason King for supplying the Declare. I cannot recall where I found it. I just remember he had posted it someplace.

Thanks, Stephen. I will try it today and will give you some feedback.

Roger and Claude works for the same company. So, don’t worry.

Sorry for the delay.

Finally, after testing it, It works fine.
I have implemented the function as it was written.

The only thing I changed is that I do not need to encode the memory block to store it. I wanted to store it as a BLOB which means that it is in binary format. So, that’s what I did using SQL injection:
Dim sql As Text
Dim imgMb As MemoryBlock
imgMb= toDataMB(mProjet.projet_photo) // my picture as IOSImage
sql = “UPDATE projet SET " + _
" projet_photo = ?1” + _
" WHERE projet_id = " + mProjet.projet_id.ToText
Catch er As iOSSQLiteException
AlertMessageBox1.Message = er.Reason
Exit Sub
End Try