Based on the Android implementation to save the picture to the local and can be displayed in the album _android

Source: Internet
Author: User

App application is more and more humane, not only the interface is beautiful and the service is also very diverse, operation is also very convenient. For example, when we use the app, we find that there is a comparison on the image to save to the phone, just click on the app to provide the Save button on it. How does this picture be saved to the local how to achieve it?

Saving a picture is simple by following these measures:

/** first default File save path *
/private static final String save_pic_path=environment.getexternalstoragestate (). Equalsignorecase (environment.media_mounted)? Environment.getexternalstoragedirectory (). GetAbsolutePath ():/mnt/sdcard;//save to SD card
private static final String Save_real_path = exact location of save_pic_path+/good/savepic;//Save

Here's how to save it, pass in the parameters:

public static void SaveFile (Bitmap BM, string fileName, String path) throws IOException {
string subforder = Save_real _path + PATH;
File Foder = new file (subforder);
if (!foder.exists ()) {
foder.mkdirs ();
}
File Mycapturefile = new file (Subforder, fileName);
if (!mycapturefile.exists ()) {
mycapturefile.createnewfile ();
} Www.jb51.net
Bufferedoutputstream bos = new Bufferedoutputstream (new FileOutputStream (Mycapturefile));
Bm.compress (Bitmap.CompressFormat.JPEG, BOS);
Bos.flush ();
Bos.close ();
}

This is preserved, but sometimes obviously saved, why enter the album when you can not see it? Anyway, I encountered such a problem, originally we in the preservation of success, but also to send a system broadcast notice mobile phone has a picture update, broadcast as follows:

Intent Intent = new Intent (intent.action_media_scanner_scan_file);
Uri uri = uri.fromfile (file);
Intent.setdata (URI);
Context.sendbroadcast (Intent)//The purpose of this broadcast is to update the library, send this broadcast into the album will be able to find your saved pictures! , remember to send you the updated file Oh

The above content is based on the implementation of Android to save pictures to the local and can be displayed in the album All the narrative, hoping to help everyone.

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.