Save Bitmap to SD card, save BitmapSD card
Public static void saveBitmapInExternalStorage (Bitmap bitmap, Context context) {try {if (IsExternalStorageAvailableAndWriteable () {File extStorage = new File (Environment. getExternalStorageDirectory (). getPath () + "/orimuse"); // orimuse is the next folder on the SD card if (! ExtStorage. exists () {extStorage. mkdirs ();} File file = new File (extStorage, System. currentTimeMillis () + ". png "); FileOutputStream fOut = new FileOutputStream (file); bitmap. compress (Bitmap. compressFormat. PNG, 90, fOut); // compress the image fOut. flush (); fOut. close (); Toast. makeText (context, "saved successfully", Toast. LENGTH_SHORT ). show ();} else {Toast. makeText (context, "failed to save", Toast. LENGTH_SHORT ). show () ;}} catch (IOException ioe) {ioe. printStackTrace ();}}
How does android save an array as an image and save it on the SD card?
Bitmap bm = BitmapFactory. decodeByteArray (byte [] data, int offset, int length); Do not forget to judge whether the array is empty.
Save ....
Public void saveFile (Bitmap bm, String fileName) throws IOException {
Private final static String ALBUM_PATH
= Environment. getExternalStorageDirectory () + "/download_test /";
File dirFile = new File (ALBUM_PATH );
If (! DirFile. exists ()){
DirFile. mkdir ();
}
File myCaptureFile = new File (ALBUM_PATH + fileName );
BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (myCaptureFile ));
Bm. compress (Bitmap. CompressFormat. JPEG, 80, bos );
Bos. flush ();
Bos. close ();
}
In android, Bitmap is saved as an image.
You can use the Bitmap. compress function to save a Bitmap object as a PNG or JPG file. Then, you can use BitmapFactory to read the data in the file and generate a Bitmap object.
The saved code is like this:
Try {
FileOutputStream out = new FileOutputStream (filename );
Bmp. compress (Bitmap. CompressFormat. PNG, 90, out );
} Catch (Exception e ){
E. printStackTrace ();
}
For more information, see the help documentation of Bitmap and BitmapFactory.