4
我有我画线画布:如何获得画布像素
//see code upd
我需要吸管工具将颜色从我的画布。我该如何制作它?
代码UPD:
private static class DrawView extends View
{
...
public DrawView(Context context) {
super(context);
setFocusable(true);
mBitmap = Bitmap.createBitmap(640, 860, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
this.setDrawingCacheEnabled(true);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
private void touch_up()
{
if(!drBool) //is true when I click pipette button
{
...
mCanvas.drawPath(mPath, mPaint); // lines draw
mPath.reset();
}else{
this.buildDrawingCache();
cBitmap = this.getDrawingCache(true);
if(cBitmap != null)
{
int clr = cBitmap.getPixel((int)x, (int)y);
Log.v("pixel", Integer.toHexString(clr));
mPaint.setColor(clr);
}else{
Log.v("pixel", "null");
}
}
drBool = false;
}
}
我只看到 “像素” - “ffaaaaaa”,或者如果我使用mCanvas.drawColor(Color.GRAY) “像素” - “ff888888”
此代码工作正常仅供drawColor,但他并不认为它必须努力通过drawPath – Leo
创建的颜色! getPixel就是这样做的。它直接从位图(即存储位图的字节数组)获取x,y处的像素,并且是您在屏幕上看到的。当drawPath方法渲染到位图时,它最终绘制像素,因此在此级别(getPixel),任何绘图调用之间没有区别。我怀疑x和y的数学可能是错误的。 – Simon