rec.picturecolumn in 2017r2

A SQLite DB is set up with “StPic” as a blob column holding a picture

dim rec As New DatabaseRecord rec.picturecolumn("StPic") = thePicture
now throws an UnsupportedFormatException in Xojo 2017r2 after working correctly for many previous releases.

Changing to

rec.blobcolumn("StPic") = thePicture

shows an error on compile “There is more than one item with this name and it is not clear to which this refers”

Cannot use the “converting picture to a text” trick found in the forum archives due to backward compatibility issues with versions of this app in circulation.

I can always compile with 2017r1.1 where the .picturecolumn still worked, but I want to compile for 64-bit and use the added features of r2

Suggestions appreciated.

[quote=346033:@Roger Clary]Changing to

rec.blobcolumn(“StPic”) = thePicture
shows an error on compile “There is more than one item with this name and it is not clear to which this refers”[/quote]
FWIW, BlobColumn takes a String, not a Picture. So you’d have to change it to something like this:

rec.BlobColumn("StPic") = thePicture.GetData(Picture.FormatJPEG, Picture.QualityHigh)

The above code gets a MemoryBlock for the Picture and MemoryBlock can convert itself to String.

Thanks, Paul. So if I save it with/…

rec.BlobColumn("StPic") = thePicture.GetData(Picture.FormatJPEG, Picture.QualityHigh)

Can I read it back simply with…

dim rs As recordset myPic = rs.Field("StPic").PictureValue

If so, then I can maintain backwards compatibility

I haven’t tried it, but it’s worth a shot. I suspect you’d need to make sure the types match, though. So for my example using JPEG, it would be like this:

myPic = rs.Field("StPic").PictureValue(Picture.FormatJPEG, Picture.QualityHigh)

Or you can just read the data directly using something like this:

myPic = Picture.FromData(rs.Field("StPic").Value.StringValue)

Initial testing indicates that I can just change

rec.picturecolumn("StPic") = thePicture

to

rec.BlobColumn("StPic") = thePicture.GetData(Picture.FormatPNG, Picture.QualityHigh)

and

myPic = rs.Field("StPic").PictureValue

will still recover both old pics saved with rec.picturecolumn and the new method.

Thanks a bunch for the speedy reply, Paul. You saved me a lot of extra work today. :slight_smile:

FOLLOW UP—
Turns out the problem was not what I thought it was at all. In

rec.picturecolumn("StPic") = thePicture

I was getting thePicture by pulling a pic which I had stored in the project. Like all of my project images, I had added a @2x to that. So I had noPic and noPic@2x in the project. Then when I did

thePicture = noPic

Xojo was confused and created the errors I was seeing. Bottom line: rec.pictureColumn still works just fine if you pass it a simple picture object.

I just posted this exact question on the case report :stuck_out_tongue:

For my purposes, I just removed the @2x element and it now works. But for future reference how would I refer to the picture so Xojo would select the correct one for hiDPI or not?

if you have the 1x and 2x then you dont have to do anything
it will pick the right one automatically

but you cant save an image (which consists of many pictures) in a “picture” column because thats a single picture

if you want to save these you’d have to save & read each element (which you can do)
see http://documentation.xojo.com/index.php/Picture.ImageCount
and http://documentation.xojo.com/index.php/Picture.IndexedImage

the indexed image page has an example of getting each individual element

you might want to save the 1x and2x into the db with suitable names and restore them from there as well

Thanks, Norman