How to set bitmap for canvas

All your problems with Audio, Video and Images.

How to set bitmap for canvas

Postby hudvin » Thu Jan 29, 2009 11:08 am

In onDraw method I want to set custom bitmap to canvas. But than I do this, I can see only empty canvas with default background. My code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private synchronized void doDraw(Canvas canvas, Paint paint) {
  3.  
  4.  
  5.  
  6.         Bitmap bmp = Bitmap.createBitmap(1024, 1024, Config.RGB_565);
  7.  
  8.                 canvas.setBitmap(bmp);
  9.  
  10.        
  11.  
  12.         canvas.drawBitmap(mapBg, 0, 0, paint);
  13.  
  14.                         Bitmap tmpBitmap;
  15.  
  16.                         int ox = pmap.globalOffset.x;
  17.  
  18.                         int oy = pmap.globalOffset.y;
  19.  
  20.                         for (int i = 0; i < 3; i++) {
  21.  
  22.                                 for (int j = 0; j < 3; j++) {
  23.  
  24.                                         tmpBitmap = pmap.getCells()[i][j];
  25.  
  26.                                         if (tmpBitmap != null) {
  27.  
  28.                                                 canvas.drawBitmap(tmpBitmap, (i) * 256
  29.  
  30.                                                                 + ox, (j) * 256
  31.  
  32.                                                                 + oy, paint);
  33.  
  34.                                         }
  35.  
  36.                                 }
  37.  
  38.                         }
  39.  
  40.         }
  41.  
  42.  
  43.  
  44.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
hudvin
Freshman
Freshman
 
Posts: 6
Joined: Wed Jan 14, 2009 3:50 pm

Top

Postby MrSnowflake » Thu Jan 29, 2009 11:29 am

maybe paint is transparent?
And creating a bitmap and setting it as background won't give you much result, as the create bitmap is empty, though I think it will be black or white.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby aneuryzma » Tue Jan 19, 2010 2:57 pm

hi,

I'm using this code and it works well. However when I test it on the phone, I get an out of memory error on VM. Are the 2 bitmaps too big to handle for my mobile phone ?

The bitmap comes from the camera of my phone.. should I reduce the pictures resolution in my camera settings ?

thanks
aneuryzma
Developer
Developer
 
Posts: 28
Joined: Wed Jan 06, 2010 10:46 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 6 guests