使用毕加索绘制带有白色背景的圆形图像

我有一些白色背景的图像和一些透明背景的图像。 当创建它们的圆形图像时,我希望它们都具有白色背景,所以基本上我想用白色像素替换图像的透明像素。

有没有办法实现这一点,而无需逐个替换像素? 这是我用于创建圆角图像的转换:

package com.mobilefootie.util; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Shader; public class RoundedTransformation implements com.squareup.picasso.Transformation { public RoundedTransformation() { } @Override public Bitmap transform(final Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size/2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; } @Override public String key() { return "rounded"; } } 

您必须为Paint设置ColorFilter (我应用GREEN以获得更好的可视化):

 BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); PorterDuff.Mode mMode = PorterDuff.Mode.OVERLAY; paint.setColorFilter(new PorterDuffColorFilter(Color.GREEN, mMode));