将android画布保存为位图

时间:2014-01-22 21:52:25

标签: android bitmap android-canvas

我想在onDraw()方法中保存canvas对象以保存为位图。请不要建议像“view.getDrawingCache(true)”这样的答案。我想将画布直接保存到位图

1 个答案:

答案 0 :(得分: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);