Bitmap
:Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
然后创建一个Canvas
从Bitmap
绘制,绘制背景颜色:
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE, PorterDuff.Mode.CLEAR);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
int top = (original.getHeight() - bitmap.getHeight()) / 2;
int left = (original.getWidth() - bitmap.getWidth()) / 2;
canvas.drawBitmap(original, top, left, paint);
Bitmap
保存到File
中。您可以使用bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
代替outputStream.write()
来存储Bitmap
。