带有位图的Canvas中的默认黑色边框

时间:2016-04-16 11:02:19

标签: android android-canvas android-bitmap

我希望Bitmap使用Canvas四舍五入,但默认情况下会获得黑色边框。 如何删除此边框。

代码

public Bitmap transform(final Bitmap source)
{
      Drawable drawable = context.getResources().getDrawable(R.drawable.dummy_image);

    float scale = Math.min(((float)drawable.getIntrinsicHeight() / source.getWidth()), ((float) drawable.getIntrinsicWidth() / source.getHeight()));

    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);

    Bitmap newBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);


    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(newBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));

    Bitmap output = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    canvas.drawCircle((drawable.getIntrinsicWidth())/2,(drawable.getIntrinsicHeight())/2, getDrawableSize()-24, paint);

    if (source != output)
    {
        source.recycle();
    }
    return output;
}

enter image description here

0 个答案:

没有答案