Skip to content

Instantly share code, notes, and snippets.

@lgyjg
Last active April 28, 2017 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgyjg/ff8cee1820643b40c8c6e08f851de1be to your computer and use it in GitHub Desktop.
Save lgyjg/ff8cee1820643b40c8c6e08f851de1be to your computer and use it in GitHub Desktop.
save bitmap object to sdcard to test
// 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();
}
}
}
@lgyjg
Copy link
Author

lgyjg commented Jun 12, 2016

在Android代码中使用如上代码来保存bitmap数据到本地

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment