Bitmap類有一compress成員,可以把bitmap儲存到一個stream中。
例如:
public void saveMyBitmap(String bitName) throws IOException {
File f = new File("/sdcard/Note/" + bitName + ".png");
f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
轉自:http://www.itstrike.cn/Question/1d603c7d-dafb-465b-bc6d-18ef4c63df42#3a29d27e-2e9b-4aff-b962-f5f92c55ae62