我有Click方法将图像保存到图库。点击"保存"该文件夹是在图库中创建的,但是当我进入图库时它会说"没有缩略图" ... 这是我的代码:
String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
File myDir = new File(root + "/PhotoEditor ");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-" + n + ".jpg";
File file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
if (sb != null) {
sb.compress(Bitmap.CompressFormat.JPEG, 90, out);
}
out.flush();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(ShowPhotoActivity.this,"Your image is saved to gallery",Toast.LENGTH_LONG).show();
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(ShowPhotoActivity.this, new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
答案 0 :(得分:0)
你能记录" file.toString()"看看你得到了什么?您可能需要传递绝对路径:file.getAbsolutePath()而不是调用file.toString()但很难诊断。您是否已使用文件管理器应用程序确认在关闭流后jpg确实存在?