image load

elitevenkat

Active Member
Licensed User
Longtime User
hi I get the following error when trying to load an image file to imageview control

java.lang.RuntimeException: Error loading bitmap.

I am uploading a image file to mysql. and read image record from mysql and trying to laod the same into the control.

following is the code for uploading into mysql

B4X:
Sub InsertImage

Dim su As StringUtils 
Dim su1 As String 
    'convert the image file to a bytes array
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput( File.DirRootExternal, "sign.png")
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    File.Copy2(InputStream1, OutputStream1)
    Dim Buffer()  As Byte 'declares an empty array
    Buffer = OutputStream1.ToBytesArray
   su1=su.EncodeBase64(Buffer)
   
    'write the image to the database
   ServerUrl="http://ctor.amwaru.in/insupdatedelete.php"   
    ExecuteRemoteQuery ("INSERT INTO sigImage(PodNo,SigImage)  VALUES(1,'" &   su1 & "')",DB_UPDATE)
End Sub


this is how i try to read the mysql record:

Case DB_SHOWIMAGE


            Dim gdt As List
           Dim cStul As StringUtils 
       Dim cTmp As String  
       Dim out As OutputStream
            gdt = parser.NextArray 'returns a list with maps

                Dim m As Map
      Dim Buffer  As InputStream 
                m = gdt.get(i)
                cTmp=m.Get("sigimage")
             Buffer. InitializeFromBytesArray(cStul.DecodeBase64(cTmp) ,0,1000)            
      out = File.OpenOutput(File.DirRootExternal,"New.png",False)
      File.Copy2(Buffer,out)
      out.close     

                ImageView1 .Bitmap=LoadBitmap(File.DirRootExternal,"New.png")
                (here i get the error)

can any one tell me where i have went wrong ?
 

ivanomonti

Expert
Licensed User
Longtime User
Please use [ code ] tags (without spaces) when posting code.
This thread should have been posted in the questions forum (unless you think that there is a bug).

The problem is in this line:
B4X:
Buffer. InitializeFromBytesArray(cStul.DecodeBase64(cTmp) ,0,1000)
It should be:
B4X:
Buffer = cStul.DecodeBase64(cTmp)

hi problem decode64,

B4X:
Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(300dip)
    Activity.AddView(sv, 0dip, 0dip, 320dip, 300dip)
    panel1.Initialize("")
    sv.Panel.AddView(panel1, 0, 0, sv.Width, 1000dip)
    canvas1.Initialize(panel1)
   Dim r As Rect
   r.Initialize(0,0,320,300)
   canvas1.DrawBitmap(c.getimage,Null,r)
    canvas1.DrawColor(Colors.ARGB(220,220,220,220))
   canvas1.DrawLine(100,0,100.0,300,Colors.RGB(50,50,50),1)
End Sub


B4X:
Sub getimage As Bitmap

   Dim bt As Bitmap
   bt.Initialize2(dc.DecodeStoB(imagebase64(0))
   Return bt
   
End Sub


image code64
B4X:
imagebase64(0) = "iVBORw0KGgoAAAANSUhEUgAAAAcAAADXCAIAAABZDtyrAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA2klEQVR4nO3IR0oDUABF0bsOx3YJKmKP3WBP7L13xYb7H7iB+5A//2d4+DX8GL5N2C8T9tPwYYr23YR9M7yasC+GZxP2yfBoeDBh7w13hlsT9sZwbbgyYS8NF4ZzE/bMcGo4MWGPDUeGQ8OBYd+E3TPsGjqGtgm7Y9g2bJmwm4YNw7oJu2ZomaJdNawYlg1LhkXDggk7b8LOGZqGWcOMYdqEnTJhJw0TJuy4YcwU7agp2hHDsAnbMEU7ZMIOmqIdMPQb+kzYXkOPCdtt6DJ169atW7du3bp1/9s/SjJxXJG3HwUAAAAASUVORK5CYII="

error

Compiling code.

Error parsing program.
Error description: Invalid number of parentheses.
Occurred on line: 21
bt.Initialize2(dc.DecodeStoB(imagebase64(0)) <<<<<<<<

Thank
 
Last edited:
Top