B4J Question How to save image on Mysql table using B4J?

Yenrod

Member
By the way Erel, I can insert new data on mysql table
but i don't know how to convert image to bytes.
some object properties from b4a are different compare b4j.

Thanks
 
Upvote 0

Yenrod

Member
Hi Erel,

This is my code, everything is fine but when I'm trying to save on my table
error appear on BufferI said that "Object converted to string"

Dim In As InputStream
Dim bmp As Image
Dim out As OutputStream
Dim bufferI() As Byte

Sub BtnBrowse_Click
Dim fileimg As String
Dim SelectImg As FileChooser
SelectImg.Initialize
'SelectImg.SetExtensionFilter("Image", "*.jpg")
SelectImg.Title = "Select your photo"
fileimg = SelectImg.ShowOpen(MainForm)

If fileimg <> "" Then
IV.SetImage(fx.LoadImageSample(File.GetFileParent(fileimg), File.GetName(fileimg), IV.Width, IV.Height))
bufferI = ImageToBytes(IV.GetImage)

End If

End Sub

Public Sub ImageToBytes(Image As B4XBitmap) As Byte()
out.InitializeToBytesArray(0)
Image.WriteToStream(out, 100, "JPEG")
out.Close
Return out.ToBytesArray
End Sub

Public Sub BytesToImage(bytes() As Byte) As B4XBitmap
In.InitializeFromBytesArray(bytes, 0, bytes.Length)
bmp.Initialize2(In)
Return bmp
End Sub
 
Upvote 0
Top