I have a database table with 1 test record in it. (it is there). I have loaded a picture into a blob field using this code
I try to read the picture to an image using this code
I get an error when the program trys to execute this line.
bmpName.Initialize2(InputStream1)
The error log is this
This is the first time I have used blobs or even a paramatised query so I do not really know where my error is originating. It may even be when I load the image to the database although no error is showing
Thanks for any help
B4X:
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(File.DirDefaultExternal, Main.strFbUID & ".png")
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(1000)
File.Copy2(InputStream1, OutputStream1)
Dim Buffer() As Byte 'declares an empty array
Buffer = OutputStream1.ToBytesArray
Dim m As Map,Table1 As List
m.Initialize
Table1.Initialize
m.Put("Name", Main.strFbName)
m.Put("PicURL", Main.strFbPhotoUrl)
m.Put("FbUID", Main.strFbUID)
m.Put("Picture",Array As Object(Buffer))
Table1.Add(m)
ec.InsertMaps(Main.dbSQL,"Users", Table1)
I try to read the picture to an image using this code
B4X:
Dim Cursor1 As Cursor
Cursor1 = dbSql.ExecQuery2("SELECT Picture FROM Users WHERE FbUID=?" , Array As String(strFbUID))
Cursor1.Position = 0
Dim Buffer() As Byte 'declare an empty byte array
Buffer = Cursor1.GetBlob("Picture")
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
bmpName.Initialize2(InputStream1)
InputStream1.Close
bmpName.Initialize3(Smiley)
Cursor1.Close
I get an error when the program trys to execute this line.
bmpName.Initialize2(InputStream1)
The error log is this
java.lang.RuntimeException: Error loading bitmap.
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:523)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at aus.anyfcsapp.joe.main.afterFirstLayout(main.java:108)
at aus.anyfcsapp.joe.main.access$000(main.java:23)
at aus.anyfcsapp.joe.main$WaitForLayout.run(main.java:86)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
This is the first time I have used blobs or even a paramatised query so I do not really know where my error is originating. It may even be when I load the image to the database although no error is showing
Thanks for any help