Previous: http://www.bkjia.com/kf/201202/119625.html
Edit (scale down, graffiti, etc.) the image and save it as an image of the specified format and size.
Post Code first:
[Java]
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 (fig. CompressFormat. PNG, 100, fos );
Fos. close ();
System. out. println ("saveBmp is here ");
} Catch (Exception e ){
E. printStackTrace ();
}
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 (fig. CompressFormat. PNG, 100, fos );
Fos. close ();
System. out. println ("saveBmp is here ");
} Catch (Exception e ){
E. printStackTrace ();
} Explanation:
1. Create a Bitmap image and specify the size;
2. Create a new Canvas on the image, draw it on the Canvas, and save it;
3. directory File to be saved. Note that if the written directory is "/sdcard/akai/", you must first create a file. mkdirs (); otherwise, No found is returned for FileOutputStream;
4. Add permissions: <uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/>
From Akai's column