-1
我的問題是,當我點擊圖片,它顯示了保存的信息,但照片不會saved.I還允許使用外部存儲WRITE_EXTERNAL_STORAGE保存圖像
public void onClick(View v) {
if(isExternalStorageWriteable()) {
FileOutputStream outputStream;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.img3);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "MyImage.png");
try {
outputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.flush();
outputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(this,"Pic Created : "+file,Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(this,"SDCard Not is Ready",Toast.LENGTH_SHORT)
.show(); } }
public boolean isExternalStorageWriteable()
{
String state = Environment.getExternalStorageState();
return Environment.MEDIA_MOUNTED.equals(state); }
你的'Toast'關於創建的圖片是錯誤的,即使發生錯誤也會顯示出來。檢查你的'logcat',可能會打印一些異常。用異常堆棧跟蹤更新你的問題 – pleft