0
寻找帮助,解答为什么位图未被此图形修改。看了很多例子,我的代码似乎与所列出的内容相匹配。我错过了什么?为什么绘制到Android画布不修改我的位图?
这是相关代码(该类在别处构造,并且drawSomething()
调用位于onTouchEvent
处理程序中)。为简洁起见,我缩短了代码:
class MyView extends View {
Bitmap mBitmap;
BitmapDrawable mBitmapDrawable;
Canvas mCanvas;
Paint mPaint;
public MyView(Context context) {
super(context);
mBitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
mBitmapDrawable = new BitmapDrawable(getResources(), mBitmap);
mCanvas = new Canvas(mBitmap);
mCanvas.setBitmap(mBitmap);
mPaint = new Paint();
mPaint.setColor(Color.parseColor("#00FF00"));
mPaint.setStrokeWidth(10);
}
public void drawSomething() {
mCanvas.drawColor(0xFF00FF00); // This should "fill" the canvas
int radius = 10;
mCanvas.drawCircle(50, 50, radius, mPaint); // This should draw a circle at (50, 50)
int count=0;
for (int i=0; i<mBitmap.getWidth(); i++)
{
for (int j=0; j<mBitmap.getHeight(); j++)
{
if (mBitmap.getPixel(i, j) > 0)
{
count += 1;
}
}
}
if (count == 0)
{
Log.v("MyApp", "Nothing was drawn!");
}
}
}
你在哪里调用'drawSomething()'? – CommonsWare
编辑说明用法。谢谢 – Jason
如果您确定此代码可能会重现此问题,我认为您应该简单地创建一个示例应用程序并将其放到github上,以便人们可以更轻松地进行尝试。 –