Canvas.initialize crashes

ehetu

Member
Licensed User
Longtime User
Ok...maybe I've been staring at it too long to see what's wrong...and I swear this code used to work!

I'm trying to put a visual timestamp on a JPG...I take the picture, save it as "1.jpg", open it back up, slap it into an imageview, move the imageview into a canvas then use the canvas.drawtext method to timestamp it. Except it never gets there and dies during the canvas.initialize invocation ("Application has stopped unexpectedly").

B4X:
   If  iview.IsInitialized = False Then
      iview.initialize("")
      Activity.AddView(iview,10,10,1600,1200)   
       iview.Gravity=Gravity.FILL
   End If 

   iview.visible = False
   iview.Bitmap=LoadBitmap(File.DirRootExternal,"1.jpg")
    cnvs.Initialize(iview)  ' CRASHES HERE!
   cnvs.DrawText(Label1.Text,30,20,Typeface.DEFAULT,15,Colors.White,"LEFT")
 

Attachments

  • CamTest.zip
    6.9 KB · Views: 186

ehetu

Member
Licensed User
Longtime User
OK...you're right. Memory exception...

I used the Initialize function thinking it was the only way to load the graphic into the canvas. I moved the initialize to the startup and tried the drawbitmap method from the the canvas to load the image but still get the same error.

I'm guessing it's trying to load an 8 Mb file into the canvas...but I thought I had trimmed it by creating a 1600x1200 view.


---------------------------------
7680000-byte external allocation too large for this process.
Out of memory: Heap Size=9927KB, Allocated=7113KB, Bitmap Size=16871KB, Limit=32768KB
Trim info: Footprint=9927KB, Allowed Footprint=9927KB, Trimmed=984KB
VM won't let us allocate 7680000 bytes
start to fill 2 buffers
GC_FOR_MALLOC freed <1K, 29% free 7113K/9927K, external 16871K/18919K, paused 15ms
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
start to fill 2 buffers
FATAL EXCEPTION: main
java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=11655KB, Allocated=7113KB, Bitmap Size=16871KB)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:695)
----------------------------------


edmond
 
Upvote 0
Top