我寫了這個代碼在指定的文件夾名稱及其保存圖像,但我想保存此圖像中畫廊/指定的文件夾名稱/圖片。可有人請幫助我..... CODE:無法將應用資產文件夾中的圖像保存到Android中的圖庫文件夾?
saveImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
saveImage(getBitmapFromAsset("save_fatwa.jpg"),
"save_fatwa.jpg");
}
});
private Bitmap getBitmapFromAsset(String strName) {
AssetManager assetManager = getAssets();
InputStream istr = null;
Bitmap bitmap = null;
try {
istr = assetManager.open(strName);
if (istr.equals(null)) {
Log.i("getBitmapFromAsset isStr", "" + istr);
bitmap = BitmapFactory.decodeStream(assetManager
.open("save_fatwa.jpg"));
} else {
bitmap = BitmapFactory.decodeStream(istr);
}
} catch (IOException e) {
e.printStackTrace();
}
// Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
private void saveImage(Bitmap finalBitmap, String imageName) {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Jamia Binoria Images");
myDir.mkdirs();
// String fname = "save_fatwa.jpg";
File file = new File(myDir, imageName);
if (file.exists()) {
Log.i("file exists", "" + imageName);
file.delete();
} else {
Log.i("file does not exists", "" + imageName);
}
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG,90,out);
// sendBroadcast(new Intent(
// Intent.ACTION_MEDIA_MOUNTED,
// Uri.parse("file://" +
// Environment.getExternalStorageDirectory())));
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
在這裏,我已經使用其他功能,從資產Folder.Please獲得的圖像,讓我知道在這個代碼添加到其保存在庫/文件夾名稱/圖片
logcat中的任何stacktrace? – donfuxx
您是否向清單文件添加了寫入和讀取外部存儲權限? – Piyush