机器人节约帆布作为位图 [英] Saving android canvas as a bitmap

查看:107
本文介绍了机器人节约帆布作为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保存的onDraw()方法Canvas对象保存为一个位图。请不要建议喜欢的答案view.getDrawingCache(真)。我想画布上直接保存到一个位图


解决方案

  //首先创建一个可变的位图 - 你决定大小
BKG = Bitmap.createBitmap(宽度,宽度,Bitmap.Config.ARGB_8888);//创建与空位图画布
帆布C =新的Canvas(BKG);//做任何你需要的图纸methoods ....我做了一个圈子
c.drawColor(mContext.getResources()的getColor(R.color.off_white));
p.setColor(象素);
c.drawCircle(宽度/ 2,宽度/ 2,宽度/ 2,p)的;//然后拉过整个画布作为一个bitmapdrawable(或位图,如果你perfer)
返回新BitmapDrawable(mContext.getResources(),BKG);

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

解决方案

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

这篇关于机器人节约帆布作为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆