[Gambas-user] Loading Picture/Image from String/Byte[] data

Patrik Karlsson patrik at trixon.se
Sat Jan 6 10:54:34 CET 2018


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180106/14339811/attachment.html>


More information about the User mailing list