Question

I need to textured some bitmap in ImageView. I use code bellow:

        Bitmap original - texture;                        
        Bitmap mask - image that I must textured;            
        Bitmap result -  result image;

        Canvas mCanvas = new Canvas(result);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);            
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        mCanvas.drawBitmap(original, 0, 0, null);
        mCanvas.drawBitmap(mask, 0, 0, paint);
        paint.setXfermode(null);            
        imgView.setImageBitmap(result);
        imgView.setScaleType(ScaleType.CENTER);

it's work but I have

mask enter image description here and texture enter image description here result image enter image description here

But I need black borders and circuit of the image. Anybody know solution how to do that?

Was it helpful?

Solution

Solution my problem was very simple. Instead

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

Need to use

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));

And everything work like charm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top