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.