i take a picture from camera, then i put it in imageview (another activity) by calling CallSubDelayed2 with
bitmap type output.
the picture displayed ok in that activity.
i'm using cameraEx class and ImageMod Code Module for maintaining proportion in imageview
but i want to save that picture to SQLlite database with Blob Type.
Sub Camera1_PictureTaken (Data() As Byte)
camEx.StartPreview 'restart preview
Dim in As InputStream
in.InitializeFromBytesArray(Data, 0, Data.Length)
Dim bmp As Bitmap
bmp.Initialize2(in)
CallSubDelayed2(ac_podbyda,"getphoto",bmp)
Activity.Finish
End Sub
activity ac_podbyda, displaying image and save to database
B4X:
Sub getphoto (byt As Bitmap)
Dim bmp As Bitmap = byt
Dim imgmodx As imgmod
imgmodx.Initialize
imgvphoto.Bitmap = imgmodx.FitBitmapToView(bmp,imgvphoto)
End Sub
B4X:
Dim ListOfMaps As List
ListOfMaps.Initialize
Dim inst As Map
inst.Initialize
inst.Put("image1", imgvphoto.Bitmap)
ListOfMaps.Add(inst)
DBUtils.InsertMaps(Starter.SQL1,"tt_photos",ListOfMaps)
I do not know what is
Dim imgmodx As imgmod
in your code. Searched the forum and did not find any Code module named imgmod for maintaining proportion in imageview
Please try the below given code. It is working fine for me.
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private oPhotoGraph() As Byte
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
oPhotoGraph = Data
If Data = Null Then
Msgbox("Unable to capture. Please try again","No picture captured")
Else
UploadPhoto
End If
camEx.StartPreview 'restart preview
End Sub
Sub UploadPhoto
ProgressDialogShow("Saving Photo to database. Please wait....")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name="insert_pic"
cmd.Parameters=Array As Object(oPhotoGraph)
reqManager.ExecuteCommand(cmd,"UploadPhoto")
End Sub
Sub Globals
Dim photo1() As Byte
End Sub
Sub getphoto (byt As Bitmap)
Dim bmp As Bitmap = byt
Dim imgmodx As imgmod
imgmodx.Initialize
imgvphoto.Bitmap = imgmodx.FitBitmapToView(bmp, imgvphoto)
End Sub
Sub getphotobyte (byt () As Byte)
photo1 = byt
End Sub
Sub btnsave_Click
Dim ListOfMaps As List
ListOfMaps.Initialize
Dim inst As Map
inst.Initialize
inst.Put("image1",photo1)
ListOfMaps.Add(inst)
DBUtils.InsertMaps(Starter.SQL1,"tt_photos",ListOfMaps)
End Sub
B4X:
Sub Camera1_PictureTaken (Data() As Byte)
camEx.StartPreview 'restart preview
Dim in As InputStream
in.InitializeFromBytesArray(Data, 0, Data.Length)
Dim bmp As Bitmap
bmp.Initialize2(in)
CallSubDelayed2(ac_podbyda, "getphoto", bmp)
CallSubDelayed2(ac_podbyda, "getphotobyte", Data)
Activity.Finish
End Sub
the problem lies in syntax to insert to database column. wrong, not working :
inst.Put("image1",Array As Object(photo1))