Anyone here able to read image from Firebird database that was sent via JRDC?
I have the following codes to send an image
B4X:
Sub Globals
Private reqM As DBRequestManager
Private Conn As String
Private txtId As EditText
End Sub
Sub btnTest_click
If(reqM.IsInitialized = False) Then reqM.Initialize(Me, Conn)
Private Id As Int
Dim Buffer() As Byte
Buffer = reqM.FileToBytes(File.DirAssets,"black.jpg")
Id = txtId.Text
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "ins_tmp"
cmd.Parameters = Array As Object(Id,Buffer)
reqM.ExecuteQuery(cmd, 0, "ins_tmp")
End Sub
It was a success operation, but when I tried to view image on Server Side with Firebird database, it returns error :
Bitmap image is not valid.
I got gift_db.jpg via sql database management for firebird. I also wrote an application to retrieved this jpg file, the size is the same with this sql management.
I will try to insert jpg file to firebird database from other application & see if this inserted file size is the same with the original one.
Sub btnTest_click
If(reqM.IsInitialized = False) Then reqM.Initialize(Me, Conn)
Private Bmp As Bitmap
Private Tmp As Bitmap
Private Out As OutputStream
Private Buffer() As Byte
Bmp = LoadBitmap(File.DirAssets,"Nature.jpg")
Buffer = reqM.ImageToBytes(Bmp)
Out = File.OpenOutput( File.DirRootExternal,"test2.jpg",False)
imgVw.Bitmap = reqM.BytesToImage(Buffer)
Tmp = imgVw.Bitmap
Tmp.WriteToStream( Out,100,"JPEG")
Msgbox("done","")
End Sub
The original file size changed after a call to sub ImageToBytes.
Attached is the sample project, just press Test button to test it.
The result was the same. File size after a call to sub ImageToBytes/FileToBytes is different from the original one. It's bigger.
If I changed image quality in sub ImageToBytes to became like this
B4X:
Public Sub ImageToBytes(Image As Bitmap) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(0)
Image.WriteToStream(out,100, "JPEG") 'this is the original code
Image.WriteToStream(out,7, "JPEG")
out.Close
Return out.ToBytesArray
End Sub
The file size produced by sub ImageToBytes for this image file (nature.jpg) is almost the same with the original one.
But with differrent image, that quality (set to 7) won't produce the same result.
Is there a way to save image to byte, exactly to the same size as the original image?