I have a canvas on which I draw lines:
//see code upd
I need to make the pipette tool which will take color from my canvas. How may I make it?
Code 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;
}
}
I see only "pixel"-"ffaaaaaa", or if I use mCanvas.drawColor(Color.GRAY) "pixel"-"ff888888"