如何清除油漆用手指在图像? [英] How to erase paint with finger on Image?

查看:99
本文介绍了如何清除油漆用手指在图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何机构可以告诉我抹去油漆的形象,在我的应用我是prepared图像的手指画,如果我想删除的油漆是,S得到的图像黑色,而不是删除图像。我的code是

 公共类MyView的扩展视图{
    INT BH = originalBitmap.getHeight();
    INT体重= originalBitmap.getWidth();
    公共MyView的(语境C){
        超级(C);
        // mBitmap = Bitmap.createScaledBitmap(originalBitmap,体重,BH,真正的);
        mBitmap = Bitmap.createBitmap(BW,BH,Bitmap.Config.ARGB_8888);
        mCanvas =新的Canvas(mBitmap);
        的mpath =新路径();
        mBitmapPaint =新的油漆(Paint.DITHER_FLAG);
        mBitmapPaint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.SRC));
    }
    公共MyView的(上下文C,INT的颜色){
        超级(C);

        mBitmap = Bitmap.createScaledBitmap(originalBitmap,体重,BH,真正的);
        mCanvas =新的Canvas(mBitmap);
        的mpath =新路径();
        mBitmapPaint =新的油漆(Paint.DITHER_FLAG);
        mBitmapPaint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.SRC));
        mCanvas.drawColor(颜色);
    }
    @覆盖
    保护无效onSizeChanged(INT W,INT小时,INT oldw,诠释oldh){
        super.onSizeChanged(W,H,oldw,oldh);
            / * mBitmap = Bitmap.createBitmap(W,H,Bitmap.Config.ARGB_8888);
            mCanvas =新的Canvas(mBitmap); * /
    }
    @覆盖
    保护无效的OnDraw(帆布油画){
        canvas.drawColor(Color.TRANSPARENT);
        canvas.drawBitmap(mBitmap,0,0,mBitmapPaint);
        canvas.drawPath(的mpath,mPaint);
    }
 

油漆擦

  mPaint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.CLEAR));
 

解决方案

您应该画在透明的自定义视图放置在原来的位图,而不是修改的一部开拓创新。这将保持它的简单。 对于,你可以做

 < RelativeLayout的....>
      < ImageView的......设为原始位本/>
      < CustomView ......利用这一点,您可以擦除过./& GT;
< / RelativeLayout的>
 

有关获得修改后的位图呼叫的 getDrawingCache()方法 RelativeLayout的。这会给你的合并位图图像。

希望这有助于。

Can any body tell me to erase the paint on the image , in my application i was prepared the finger painting on image, if i want erase the paint it,s getting black color on image instead of erasing the image. my code is

    public class MyView extends View {
    int bh = originalBitmap.getHeight();
    int bw = originalBitmap.getWidth();
    public MyView(Context c)  {
        super(c);
        //mBitmap = Bitmap.createScaledBitmap(originalBitmap,bw,bh,true);
        mBitmap = Bitmap.createBitmap(bw,bh,Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);
        mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
    }
    public MyView (Context c, int color)  {  
        super(c);

        mBitmap = Bitmap.createScaledBitmap(originalBitmap,bw,bh,true);
        mCanvas = new Canvas(mBitmap);
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);
        mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)) ;
        mCanvas.drawColor(color);
    } 
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);           
            /*mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
            mCanvas = new Canvas(mBitmap);*/
    }
    @Override 
    protected void onDraw(Canvas canvas) {   
        canvas.drawColor(Color.TRANSPARENT);
        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
        canvas.drawPath(mPath, mPaint);
    }

for paint erase

 mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

解决方案

You should draw on a transparent custom view placed over the original bitmap instead of modifying the orignal. That will keep it simple. For that you can do

<RelativeLayout ....>
      <ImageView ......set original bitmap to this/>
      <CustomView ...... draw on this, you can erase too./>
</RelativeLayout>

For getting the modified bitmap call the getDrawingCache() method on that RelativeLayout. That will give you the combined bitmap image.

Hope this helps.

这篇关于如何清除油漆用手指在图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆