我有一個將位圖保存到文件的問題。 我的方法是這樣的:將位圖保存到文件並返回包含位圖圖像的文件
private File savebitmap(Bitmap bmp) {
String extStorageDirectory = Environment.getExternalStorageDirectory()
.toString();
OutputStream outStream = null;
File file = new File(bmp + ".png");
if (file.exists()) {
file.delete();
file = new File(extStorageDirectory, bmp + ".png");
Log.e("file exist", "" + file + ",Bitmap= " + bmp);
}
try {
outStream = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Log.e("file", "" + file);
return file;
}
它給了我錯誤file.I的正在調用該方法是這樣的:
Drawable d = iv.getDrawable();
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
File file = savebitmap(bitmap);
請幫我...
這是排什麼文件文件=新的文件(BMP +」的含義。 PNG「);? – 2013-03-15 09:44:35
定義「文件錯誤」(即帖子堆棧跟蹤) – njzk2 2013-03-15 09:45:28
@FestusTamakloe我猜他錯誤地認爲'bmp.toString()'將返回bmp的名稱, – 2013-03-15 09:48:22