Android Question RDC : Problem when reading Image in Firebird Db

incendio

Well-Known Member
Licensed User
Longtime User
Hi all,

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.

How to solve this problem?
Thanks in advance.
 

incendio

Well-Known Member
Licensed User
Longtime User
Found out that my application from Server side only support display BMP file type, while image that was sent was jpeg file type.

But why the image size on database was not the same size with the original one? Size in database almost twice size compare to the original one.
 
Last edited:
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
What do you mean by compare blob size?

Why i did was retrieved blob field from database & save it to an image file than compare the image size with the original one.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Attached are the image files.
1) gift.jpg ->original image
2) gift_db.jpg ->image from database
 

Attachments

  • gift_db.jpg
    gift_db.jpg
    352.1 KB · Views: 200
  • gift.JPG
    gift.JPG
    185.9 KB · Views: 212
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
How did you get gift_db.jpg? You must get it with RDC to test it.
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.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have tried to insert jpg file to firebird database from other application (not RDC) & then retrieved it with same tool and compared the file size.

The file size from database & the original one are the same.

So I guest there are an extra bytes added by DBRequestManager when sent it with RDC.

Is it possible to send image without changing in its size?
 
Last edited:
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
From where then this extra bytes came from? Could it be from JDBC?

When I sent data to firebird (not via RDC), it used direct connection to firebird, not via JDBC. I will try to send again via JDBC.

Have you experience same problem with other database, perhaps with mySQL?
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I did a simple test with these code
B4X:
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.
 

Attachments

  • TestRDC.zip
    347.1 KB · Views: 205
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Don't use ImageToBytes if you want to upload an existing file. Use FileToBytes instead.
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?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top