picture.FromData

In my quest to move to Xojo 2018, I have encountered the following issue with the following code for mImage as Picture:

[code]Dim a as string = rs.Field(“Picture”).StringValue
a = DecodeHex(a)
mImage = Picture.FromData(a)

If(mImage <> Nil) then
Graphics.DrawPicture(mImage,Canvas1.Left,Canvas1.Top,Canvas1.Width,Canvas1.Height,0,0,mImage.Width,mImage.Height)
end if
[/code]

mImage remains Nil in Xojo 2018.

What is the appropriate way to code this in the Xojo 2018?

can you attribute this directly to 2018? (as in does it work in a previous version of Xojo?)
if not, are you sure the you properly encoded the picture, and that it wasn’t altered due to text encoding (UTF-8 etc)?
Are you sure that “a” actually has a value, and that value hasn’t been truncated for example?

[quote=389493:@Dave S]
can you attribute this directly to 2018? (as in does it work in a previous version of Xojo?)
if not, are you sure the you properly encoded the picture, and that it wasn’t altered due to text encoding (UTF-8 etc)?
Are you sure that “a” actually has a value, and that value hasn’t been truncated for example?[/quote]
I am running this on the same database, same record using Xojo 2013 r3.3 and Xojo 2018 r1. The value for mImage in 2018 is Nil and displays the image in 2013.

When I inspect the string value of ‘a’ as text in Xojo 2013, I get the following information:

Encoding: Nil
Length: 213752
Length (Bytes): 213752

and all the text is visible in letters and numbers obviously hex encoded as written.

When I inspect the string value of ‘a’ as text in Xojo 2018, I get the following information:

Encoding: Nil
Length: 106875
Length (Bytes): 106875

and all the text is visible primarily diamonds with question marks and I can read words such as XPhotoshop 3.0 and Photo Booth within the text.

Is this hex code somehow being decoded when being retrieved?

When I comment out the following line:

a = DecodeHex(a)

the image is displayed.

Also, there seems to be no difference in:

Dim a as string = rs.Field("Picture").StringValue

and

Dim a as string = rs.Field("Picture").NativeValue

Not sure exactly why, but the reverse procedure used to store the image is not working correctly in Xojo 2018 but works in Xojo 2013:

Dim mb As MemoryBlock If mImage <> Nil Then // Get the image data mb = "\\x"+EncodeHex(mImage.GetData(Picture.FormatJPEG, Picture.QualityHigh)) rs.Field("picture").Value = mb End If

Upon working with this data a little longer, I find some interesting and strange behavior.

The image stored with Xojo 2013 but read with Xojo 2018 needs this line commented out:

a = DecodeHex(a)

but if the image is stored using Xojo 2018, then the image cannot be viewed using Xojo 2018 unless the above line is active.

If the image is stored using Xojo 2018 and then retrieved from the database using Xojo 2013, it seems that the Hex data is retrieved correctly however DecodeHex appears to decode the hex code into proper hex code, so if you run DecodeHex two times using Xojo 2013, the photo can be viewed.