[Gambas-user] Loading Picture/Image from String/Byte[] data
Benoît Minisini
g4mba5 at gmail.com
Sat Jan 6 12:55:20 CET 2018
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.txt")
> 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
More information about the User
mailing list