Android Image Drawing (v) Canvas Save as a picture of the specified format/size _android

Source: Internet
Author: User
Edit (shrink, doodle, etc.) the picture and save it to a picture of the specified format and size.
Post Code First
Copy Code code as follows:

Bitmap bmp = Bitmap.createbitmap (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, FOS);
Fos.close ();
System.out.println ("Savebmp is Here");
catch (Exception e) {
E.printstacktrace ();
}

explain
1, first create a bitmap picture, and specify the size;
2, create a new canvas canvas on the picture, then draw on the canvas, and save it;
3, need to save the directory file, note If you write the directory such as "/sdcard/akai/" if it does not exist, first create (File.mkdirs ()), or FileOutputStream will be the error no found;
4, need to add permissions: <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.