android中Bitmap对象怎么保存为文件?

 

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

你可能感兴趣的:(Android)