我已将此代码编写为指定文件夹名称中的保存图像,但我想将此图像保存在图库/指定FolderName / Image 中。有人请帮助我..... 的 CODE:
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();
}
}
这里我使用了另一个函数从Assets Folder获取图像。请让我知道在此代码中添加什么以将其保存在Gallery / FolderName / Image
答案 0 :(得分:0)
为manifest.xml文件添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
以下是link检查