Thursday, 24 January 2019

Android Masks with two images

I'm looking for recommendations on how to do this, I've been trying with a couple of ideas with no luck.

I have this mask:

And this image:

end result should be:

I just want to change the color of the image with the mask.

Update: 01/22:

After a couple of tries, I made some progress. Here is my current code:

Bitmap carBaseBitmap = BitmapFactory.decodeResource(getResources(), model);
Bitmap maskBitmap = BitmapFactory.decodeResource(getResources(), overlay);
Bitmap finalFinal = Bitmap.createBitmap(maskBitmap.getWidth(), maskBitmap.getHeight(),  Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(finalFinal);

ColorMatrix colorMatrix = new ColorMatrix();
float[] colorTransform = getCarColor();
colorMatrix.set(colorTransform);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);

Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setXfermode(new PorterDuffXfermode(Mode.OVERLAY));

paint.setColorFilter(filter);

canvas.drawBitmap(carBaseBitmap, 0.0f, 0.0f, null);
canvas.drawBitmap(maskBitmap, 0.0f, 0.0f, paint);

getColor method returns:

float[] colorFilter = {
    1, 0, 0, 0, 20,
    0, 1, 0, 0, 61,
    0, 0, 1, 0, 184,
    0, 0, 0, 1, 0,
};

and the end results is:



from Android Masks with two images

No comments:

Post a Comment