我想創建一個onClick事件,通過點擊按鈕將圖像視圖保存到手機圖庫中,下面是我的代碼。它不保存到畫廊,任何人都可以幫我弄清楚爲什麼?如何將我的imageView圖像保存到圖庫中(Android開發)
sharebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View b) {
// TODO Auto-generated method stub
//attempt to save the image
b = findViewById(R.id.imageView);
b.setDrawingCacheEnabled(true);
Bitmap bitmap = b.getDrawingCache();
//File file = new File("/DCIM/Camera/image.jpg");
File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg");
try
{
cachePath.createNewFile();
FileOutputStream ostream = new FileOutputStream(cachePath);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
你有沒有給你的清單文件的寫入權限。 – Raghunandan 2013-03-13 05:01:24