Android save the picture to the local and can be displayed in the album

label Android Applicationpicture
437 people read comment(0) Collection report

App application is more and more humane: beautiful interface, diversified services, the operation is also very convenient. For example, when we use the app, we found that there is a comparison of the picture to save to the phone, as long as the point of the app provided on the Save button on it. That this picture save to the local how to achieve it?

Save the picture is very simple, the method is as follows:

First, a default file path / * * * /
Private static final string save pic SAVE_PIC_PATH=Environment.getExternalStorageState) (.EqualsIgnoreCase Environment.MEDIA_MOUNTED mounted? Environment.getExternalStorageDirectory ().GetAbsolutePath (): "/ MNT / sdcard"; / / save to SD card
Private static final String SAVE_REAL_PATH SAVE_PIC_PATH+ = "/good/savePic"; / / the exact location of preservation

Here is the way to save the incoming parameters on it:

Static void saveFile public (BM Bitmap, fileName String, path String) IOException throws {
SubForder String = SAVE_REAL_PATH + path;
Foder File = File new (subForder);
If (! Foder.exists ()) {
Foder.mkdirs ();
MyCaptureFile File = File new (subForder, fileName);
If (! MyCaptureFile.exists ()) {
MyCaptureFile.createNewFile ();
BOS BufferedOutputStream = BufferedOutputStream new (FileOutputStream new (myCaptureFile));
Bm.compress (Bitmap.CompressFormat.JPEG, 80, BOS);
Bos.flush ();
Bos.close ();

This will save the good, but sometimes when it is saved, why not enter the album when you can not see it? Anyway, I encountered such a problem, the original after we have successfully saved, but also sent a system to broadcast the phone has a picture update, broadcast as follows:

Intent Intent = Intent new (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
URI Uri = Uri.fromFile (file);
Intent.setData (URI);
Context.sendBroadcast (intent); / / this broadcast is updated Gallery, the hair of the radio into the album you can find your saved images. , remember to send you updated file oh

step on
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • visit51225 times
    • Integral:Two thousand three hundred and twenty-six
    • Grade
    • Rank:9635th name
    • original187
    • Reproduced:37
    • Translation:1
    • Comments:13
    Classification of articles
    Latest comments