In a desktop app, I use the very easy and convenient methods of Michel Bujardet, ‘PictureToString’ and ‘StringToPicture’ to store and retrieve pictures in a sqlite database.
Now, I want to use this database in a iPad app. I managed to use iTune to pass a copy of the database to the ios app and all went smoothly… except for the pictures.
Is there a way to get an IOSImage from a database text field ?
You might be able to convert the text to a picture by first converting it to a MemoryBlock (using Xojo.Core.TextEncoding.ConvertTextToData) and then creating a picture from the MemoryBlock (using iOSImage.FromData).
I think it would be better to store it in the DB as binary data and then just fetch it directly to a MemoryBlock using SQLiteDatabaseField.NativeValue. You might try this on your “TEXT” column in case it actually contains binary data and not text.
[quote=211028:@Gilles Rioux]In a desktop app, I use the very easy and convenient methods of Michel Bujardet, ‘PictureToString’ and ‘StringToPicture’ to store and retrieve pictures in a sqlite database.
Now, I want to use this database in a iPad app. I managed to use iTune to pass a copy of the database to the ios app and all went smoothly… except for the pictures.
Is there a way to get an IOSImage from a database text field ?[/quote]
I believe I picked these methods from a 2013 Dave S’s post. It is probably possible to adapt them to iOS.
I cannot run Xojo iOS because Xojo is not yet compatible with XCode 7 I had to install in El Capitan, so I won’t be able to do it myself.
But I have had a look at the code closer and I think it should be possible.
dim tx As text = rs.Field("photo").TextValue
if tx <> "" then
dim mb as Xojo.Core.MemoryBlock
mb = xojo.core.TextEncoding.UTF8.ConvertTextToData(tx)
n.image = iOSImage.FromData(mb)
end
but it failed on IOSImage.FromData with a xojo.core.BadDataException. Note that I use the same sqlite database with my desktop app and it works perfectly.
If the data is in the DB is not actually UTF8, then that code will not result in an image. Have you tried using rs.Field(“photo”).NativeValue and then using that with FromData?
Since it is in the ‘old’ framework, could it make a difference when putting a STRING in a TEXT object ?[/quote]
You forgot the most important : in your Desktop method, EncodeBase64 turns your data into compatible text. I told you to look for Kem’s method to do the same. It is not that difficult to adapt the method you are using now.
I will try setting up Xojo and XCode on my laptop to experiment in iOS, but I believe it is possible to use compatible code. Especially since you probably have all the pictures in your database already, and you better have the same format.
I inserted the following instructions in my IOS app to translate a sqlite string field to an IOSImage:
dim tx As text = rs.Field("photo").TextValue
if tx <> "" then
dim mb as Xojo.Core.MemoryBlock
mb = DecodeBase64(tx)
myImage = iOSImage.FromData(mb)
end