我希望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;
}