【发布时间】:2013-12-12 11:11:22
【问题描述】:
我的应用程序将照片保存到Gallery,但Gallery 看不到这些照片。我使用文件管理器来检查现有的,它们就在那里!我可以从文件管理器打开它们,但不是Gallery。
我用来保存图片的代码:
public static void saveImg(long pid, ImageView picture, Context context) {
File file = new File(Environment.getExternalStorageDirectory() + "/Lackrosy/" + pid + ".jpeg");
File dir = new File(Environment.getExternalStorageDirectory() + "/Lackrosy/");
try {
if (!dir.exists())
dir.mkdir();
picture.buildDrawingCache();
Bitmap bmap = picture.getDrawingCache();
FileOutputStream out = new FileOutputStream(file);
bmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
Log.d("palval", "Photo saved: " + file.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
Log.e("palval", e.toString());
file.delete();
Toast.makeText(context, "Image not saved", Toast.LENGTH_SHORT).show();
}
}
【问题讨论】:
标签: android image save visibility android-gallery