无法从应用程序文件夹资产图像保存到库文件夹中的Android? [英] Failed to save image from app assets folder to Gallery Folder in Android?
本文介绍了无法从应用程序文件夹资产图像保存到库文件夹中的Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了这个code在指定的文件夹名称及其保存图像,但我想在画廊/指定的文件夹名称/图片保存此图像。可有人请帮助我.....
code:
I have written this code its saving image in specified folder name but i want to save this image in Gallery/Specified FolderName/Image.Can someone please help me ..... 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();
}
}
在这里,我已经使用其他功能从资产中获得Folder.Please图片让我知道在这个code添加到其保存在库/文件夹名称/图片
Here i have used another function to get images from Assets Folder.Please let me know what to add in this code to save it in Gallery/FolderName/Image
推荐答案
添加到许可文件mainfest.xml
Add Permission to mainfest.xml file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
下面是一个链接检查此
这篇关于无法从应用程序文件夹资产图像保存到库文件夹中的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文