[Gambas-user] Loading Picture/Image from String/Byte[] data
Patrik Karlsson
patrik at trixon.se
Sat Jan 6 13:36:34 CET 2018
2018-01-06 12:55 GMT+01:00 Benoît Minisini <g4mba5 at gmail.com>:
> Le 06/01/2018 à 10:54, Patrik Karlsson a écrit :
>
>> Hi there!
>>
>> I have been away from Gambas for a while but now I'm looking into a
>> gambas client to a java server.
>> The goal is to restore a binary file (image) which is base64 encoded and
>> serialized to json.
>>
>> I can load the image in the Gambas Client if I first store the file
>> content and load it as usual,
>> but I would like to avoid generating a temp file and read it directly
>> since I already have its content loaded.
>>
>> Is it possible to load a Picture/Image from String/Byte[] data that
>> represents a file?
>>
>> Option 1 below works, but I would like to use something that does not
>> include generating a file.
>> Option 2 is me poking around without any success.
>>
>> Public Sub Button1_Click()
>>
>> Dim javaGeneratedBase64EncodedImageFile As String
>> Dim decodedBase64 As String
>> Dim tempImagePath As String = Temp()
>> Dim fileByteArray As Byte[]
>> Dim i As Integer
>> Dim p As Pointer
>> Dim hFile As File
>>
>> javaGeneratedBase64EncodedImageFile = File.Load("/home/pata/base64.t
>> xt")
>> decodedBase64 = UnBase64(javaGeneratedBase64EncodedImageFile)
>> fileByteArray = Byte[].FromString(decodedBase64)
>> Print tempImagePath
>> ' option 1
>> File.Save(tempImagePath, decodedBase64)
>> PictureBox1.Picture = Picture.Load(tempImagePath)
>>
>> ' option 2
>> p = VarPtr(decodedBase64)
>> hFile = Open Memory p For Read
>>
>> Close #hFile
>> ' end of option 2
>>
>> For i = 0 To fileByteArray.Length - 1
>> 'Print fileByteArray[i]
>> Next
>>
>> Print fileByteArray.Length
>> Print Now
>>
>> End
>>
>>
> I can add some methods to the Image and/or Picture class for that.
>
> --
> Benoît Minisini
>
That would be great! I'll stick to using a temp file until its done.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180106/e4365a1d/attachment.html>
More information about the User
mailing list