Camera - Out of Memory

stu14t

Active Member
Licensed User
Longtime User
I'm having a play around with the Camera lib 2.0 and CameraEx Class example posted by Erel.

I've modified the code to place the picture taken onto a panel and then initialise a canvas to draw a filled rectangle and then write information on that rectangle and save the image.

All works fine until I take a second picture and I get an out of memory from the bmp.Initialize2(In).

I have tried to recycle the bitmap but that makes no difference but I think the problem maybe because I initialise the bitmap again causing multiple instances of the bitmap and causing the out of memory? is that the case?

B4X:
Sub Camera1_PictureTaken (Data() As Byte)

   
   Dim out As OutputStream   
   Dim In As InputStream
   Dim filename As String = "Test.JPG"
   Dim dir As String = File.DirRootExternal   
   In.InitializeFromBytesArray(Data, 0, Data.Length)
   bmp.Initialize2(In)
   Panel2.SetBackgroundImage(bmp)
   canv1.Initialize(Panel2)
   rect1.Initialize(0,710dip,1050dip,760dip)
   canv1.DrawRect(rect1,Colors.Black,True,5dip)
   canv1.DrawText("Some kind of information 15/05/2013 16:32",100dip,750dip,Typeface.DEFAULT_BOLD,50,Colors.White,"LEFT")
   Panel2.Invalidate
   out = File.OpenOutput(dir,filename , False)
   canv1.Bitmap.WriteToStream(out,100,"JPEG")
   out.Close
   IO.recycle(bmp)
   
   camEx.StartPreview 'restart preview
   
   'send a broadcast intent to the media scanner to force it to scan the saved file.
   Dim Phone As Phone
   Dim i As Intent
   i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & File.Combine(dir, filename))
   Phone.SendBroadcastIntent(i)
   ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
End Sub
 
Top