Android uses bitmap to generate key code for new images

Source: Internet
Author: User

1. Key code Copy codeThe Code is as follows: // R. drawable. test is an image of the current project.
Bitmap bitmap = BitmapFactory. decodeResource (getResources (),
R. drawable. test );
FileOutputStream fos = null;
Try
{
File file = new File ("/mnt/sdcard/testfile ");
If (! File. exists ())
{
File. mkdir ();
}
Fos = new FileOutputStream ("/mnt/sdcard/testfile/test.jpg ");
// Bitmap. CompressFormat. PNG
Bitmap. compress (Bitmap. CompressFormat. JPEG, 100, fos );
} Catch (FileNotFoundException e)
{
E. printStackTrace ();
}

2. Permissions Copy codeThe Code is as follows: <uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/>
<Uses-permission android: name = "android. permission. MOUNT_UNMOUNT_FILESYSTEMS"/>

Note: A recently written applet is about image scaling. after scaling, you can generate a new image in the notebook, which can only be downloaded from resources.

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.