创建具有黑色剩余区域问题的新位图

时间:2013-03-13 04:31:27

标签: android canvas bitmap

我必须在用户做一些事情后用原始图像创建新的位图,如缩放,旋转,拖动。我有一个框架边框,只有部分原始图像放在框架上。问题是框​​架的剩余区域是黑色的,我希望它可以是透明的或白色的。怎么做?提前谢谢。

enter image description here enter image description here

public Bitmap createBitmap(final Matrix pMatrix, final Bitmap pSourceBitmap){

  Bitmap bmp = Bitmap.createBitmap(width, height, pSourceBitmap.getConfig());

Canvas canvas = new Canvas(bmp);
  canvas.drawBitmap(pSourceBitmap, pMatrix, new Paint());

  return bmp;
 }

1 个答案:

答案 0 :(得分:1)

使剩余部分透明

使用以下代码

public Bitmap createBitmap(final Matrix pMatrix, final Bitmap pSourceBitmap)
{
     Bitmap.Config conf = Bitmap.Config.ARGB_8888; 
     Bitmap bmp= Bitmap.createBitmap(width, height, conf); 
     Canvas canvas = new Canvas(bmp);
     canvas.drawBitmap(pSourceBitmap, pMatrix, new Paint());

     return bmp;
}