3
我想繪製一個具有特定形狀的面具的圖像。 我使用Facebook的庫壁畫,這裏是代碼:android drawBitmap和PorterDuff.Mode.DST_IN,應該是透明的區域是黑色的
ImageRequest request = builder.setPostprocessor(new BasePostprocessor() {
@Override
public String getName() {
return "ChatViewImageProcessor";
}
@Override
public void process(Bitmap bitmap) {
int bitmap_width = bitmap.getWidth();
int bitmap_height = bitmap.getHeight();
ViewGroup.LayoutParams params = iv.getLayoutParams();
if (width == -1 && height == -1) {//not relavant with question
horizontal[0] = bitmap_width >= bitmap_height;
params.width = horizontal[0] ? max_image_size : (int) (max_image_size * 1.0 * bitmap_width/bitmap_height);
params.height = (horizontal[0] ? (int) (max_image_size * 1.0 * bitmap_height/bitmap_width) : max_image_size);
}
Bitmap temp = Bitmap.createBitmap(params.width, params.height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(temp);
if (bg != null) {
bg.setBounds(0, 0, params.width, params.height);
bg.draw(canvas);
}
Logger.out("temp[0,0]:" + Util.getColorNote(temp.getPixel(0, 0), true));
canvas = new Canvas(bitmap);
Rect src = new Rect(0, 0, temp.getWidth(), temp.getHeight());
Rect dst = new Rect(0, 0, bitmap_width, bitmap_height);
canvas.drawBitmap(temp, src, dst, paint);//<----------problem here
temp.recycle();
Logger.out("result[0,0]:" + Util.getColorNote(bitmap.getPixel(0, 0), true));
}
}).build();
PipelineDraweeController controller = (PipelineDraweeController)
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setOldController(iv.getController())
.build();
iv.setController(controller);
此代碼適用於5.0.2就好了... ... 我不能發佈的形象在這裏,看到http://i.stack.imgur.com/9DBbj.jpg
但失敗在4.4.4和4.1.2上。 我不能在這裏發佈圖片,看http://i.stack.imgur.com/8wbLp.jpg
我還打印了左上角像素的顏色「temp」,並在4.4.2上修剪了5.0.2上的「位圖」,即#00000000和#00000000。 4 4.1.2他們是#00000000和#FF000000