先贴代码:
代码如下:
Bitmap bmp = Bitmap.createBitmap(480, 800, Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
canvas.drawBitmap(this.bmp, matrix, paint);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
File file = new File("/sdcard/akai/");
if(!file.exists())
file.mkdirs();
try {
FileOutputStream fos = new FileOutputStream(file.getPath() + "/2.png");
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
System.out.println("saveBmp is here");
} catch (Exception e) {
e.printStackTrace();
}
解释:
1、首先创建一个Bitmap图片,并指定大小;
2、在该图片上创建一个新的画布Canvas,然后在画布上绘制,并保存即可;
3、需要保存的目录File,注意如果写的目录如“/sdcard/akai/”如果不存在的话,要先创建(file.mkdirs()),否则FileOutputStream会报错No found;
4、需要添加权限:uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/