2
我想擦擦Image.Actually我有两个图像一个在前景和另一个在背景当我擦地形图像然后背景图像将不得不如何来做?我在这里发现了很多,但不能得到解决方案呢。有人请帮我解决我的问题。 我尝试这样做:如何擦图像?
public class MainActivity extends Activity {
ImageView img;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// img = (ImageView) findViewById(R.id.img);
//
// new Panel(this);
setContentView(new Panel(this));
}
class Panel extends View {
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mPaint;
Bitmap bitmap;
Canvas pcanvas;
int x = 0;
int y = 0;
int r = 0;
public Panel(Context context) {
super(context);
Log.v("Panel", ">>>>>>");
setFocusable(true);
setBackgroundColor(Color.MAGENTA);
// setting paint
mPaint = new Paint();
mPaint.setAlpha(1);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
mPaint.setAntiAlias(true);
// getting image from resources
Resources r = this.getContext().getResources();
Bitmap bm = BitmapFactory.decodeResource(getResources(),
R.drawable.verse);
// converting image bitmap into mutable bitmap
// bitmap = Bitmap.createBitmap(295, 260, Config.ARGB_8888);
bitmap = Bitmap.createBitmap(185, 120, Config.ARGB_8888);
pcanvas = new Canvas();
pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap
pcanvas.drawBitmap(bm, 0, 0, null);
}
@Override
protected void onDraw(Canvas canvas) {
// draw a circle that is erasing bitmap
// pcanvas.drawCircle(x, y, r, mPaint);
pcanvas.drawColor(color.transparent);
canvas.drawBitmap(bitmap, 0, 0, null);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// set paramete to draw circle on touch event
x = (int) event.getX();
y = (int) event.getY();
r = 20;
// Atlast invalidate canvas
invalidate();
return true;
}
}
}
你能请告诉我,我应该在哪里将我的图像放入您在链接中提供给我的代码中? – Biginner
对不起,现在可能会有效。但是你可以总是把像素设置为透明 – tilpner