Last active
April 28, 2017 10:34
-
-
Save lgyjg/ff8cee1820643b40c8c6e08f851de1be to your computer and use it in GitHub Desktop.
save bitmap object to sdcard to test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// need permission | |
// <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | |
// <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> | |
public void saveMyBitmap(Bitmap mBitmap,String bitName) { | |
File f = new File( "/sdcard/Test/"+bitName + ".jpg"); | |
FileOutputStream fOut = null; | |
try { | |
fOut = new FileOutputStream(f); | |
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut); | |
fOut.flush(); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
if (fOut == null) return; | |
try { | |
fOut.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在Android代码中使用如上代码来保存bitmap数据到本地