Morya
Morya

Reputation: 346

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 bitmap

Upvotes: 1

Views: 273

Answers (1)

Martin
Martin

Reputation: 4816

// 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);

Upvotes: 1

Related Questions