我想创建一个空位图并为该位图设置一个 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
这是有关该主题的官方文档:Custom Drawing
https://stackoverflow.com/questions/5663671/