【发布时间】:2011-08-05 12:58:50
【问题描述】:
我想创建一个空位图并为该位图设置一个画布,然后在该位图上绘制任何形状。
【问题讨论】:
标签: android bitmap drawing android-canvas
我想创建一个空位图并为该位图设置一个画布,然后在该位图上绘制任何形状。
【问题讨论】:
标签: android bitmap drawing android-canvas
这可能比你想象的要简单:
int w = WIDTH_PX, h = HEIGHT_PX;
Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
Canvas canvas = new Canvas(bmp);
// ready to draw on that bitmap through that canvas
这是我在该主题上找到的一系列教程:Drawing with Canvas Series
【讨论】:
不要使用 Bitmap.Config.ARGB_8888
改为使用 int w = WIDTH_PX, h = HEIGHT_PX;
Bitmap.Config conf = Bitmap.Config.ARGB_4444; // see other conf types
Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
Canvas canvas = new Canvas(bmp);
// ready to draw on that bitmap through that canvas
在处理更多位图或大型位图时,ARGB_8888 会使您陷入 OutOfMemory 问题。 或者更好的是,尽量避免使用 ARGB 选项本身。
【讨论】: