Skip to content Skip to sidebar Skip to footer

Saving Android Canvas As A Bitmap

I want to save the canvas object in onDraw() method to be saved as a bitmap. Please do not suggest answers like 'view.getDrawingCache(true)' .I want to save canvas directly to a b

Solution 1:

// first create a mutable bitmap - you determine the size
bkg = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);

// create a canvas with that empty bitmap
Canvas c = new Canvas(bkg);

// do whatever drawing methoods you need....I did a circle
c.drawColor(mContext.getResources().getColor(R.color.off_white));
p.setColor(pixel);
c.drawCircle(width / 2, width / 2, width / 2, p);

// then pull off the entire canvas as a bitmapdrawable (or bitmap, if you perfer)
return new BitmapDrawable(mContext.getResources(), bkg);

Post a Comment for "Saving Android Canvas As A Bitmap"