Creating a resized bitmap using PlatformBitmapFactory doesn't have alpha value
I'm trying to mask a bitmap using a 9patch image to shape it into a custom shape.
This is what I've tried but the result bitmap returns black pixels where the area is masked.
Doesn't PlatformBitmapFactor create a bitmap with alpha value?
@Override
public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(mWidth, mHeight);
try {
Bitmap result = bitmapRef.get();
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setFilterBitmap(false);
canvas.drawBitmap(sourceBitmap, 0, 0, paint);
mask.setBounds(0, 0, mWidth, mHeight);
mask.getPaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
mask.draw(canvas);
return CloseableReference.cloneOrNull(bitmapRef);
} finally {
CloseableReference.closeSafely(bitmapRef);
}
}
Bitmap should be ARGB_8888.
What color is set to mask.getPaint()? On some Samsung devices default paint color is FF000000, i.e. black, not transparent. Can you do mask.getPaint().setColor(0) before calling mask.draw?
Also, I don't see what is mask doing exactly, so can't provide more help without having more details.
Sorry for the late response.
mask is a NinePatchDrawable created from resource file, which I don't set any color to - meaning I'm using as is once it's created.
Can you try this:
result.setHasAlpha(true);
Let us know if that works.
This works. Thanks!
How do you manipulate the position of the bitmap to be drawn - similar to center crop