fresco
fresco copied to clipboard
handle bitmap in postprocessor will lead to the bitmap has a black background
I try to show image with a bubble shape. And handle the bitmap in postprocessor. It runs normally on 5.0. But the image has a black background color on 4.4.2 even I set the background color to transparent.
Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
public CloseableReference<Bitmap> process(Bitmap bitmap, PlatformBitmapFactory platformBitmapFactory) {
Matrix matrix = new Matrix();
if (mScale != 1) {
matrix.postScale(mScale, mScale);
}
CloseableReference<Bitmap> bitmapReference = platformBitmapFactory.createBitmap(mWidth, mHeight);
Canvas canvas = new Canvas(bitmapReference.get());
Resources resources = mRootView.getResources();
NinePatchDrawable drawable = (NinePatchDrawable) resources.getDrawable(getBubbleResource());
if (drawable != null) {
drawable.setBounds(0, 0, mWidth, mHeight);
drawable.draw(canvas);
}
canvas.drawBitmap(bitmap, matrix, mPaint);
return CloseableReference.cloneOrNull(bitmapReference);
}

Do bitmapReference.get().setHasAlpha(true);