0
我想将画布对象保存为onDraw()方法以保存为位图。请不要建议喜欢回答“view.getDrawingCache(真)”。我想直接保存画布位图将android画布保存为位图
我想将画布对象保存为onDraw()方法以保存为位图。请不要建议喜欢回答“view.getDrawingCache(真)”。我想直接保存画布位图将android画布保存为位图
// 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);
“我要保存的onDraw画布对象()方法来保存为位图” - 这对我来说没有多大意义。你想达到什么目的? – CommonsWare
可能的重复:http://stackoverflow.com/questions/7442610/how-to-save-the-image-from-canvas-code-in-android-application – vbo
getDrawingCache()有什么问题?当我需要抓取视图的可见资源时,这对我来说很好。但如果你真的想要整个画布,看到我的答案 – Martin