【发布时间】:2016-09-20 23:15:38
【问题描述】:
我有点击方法将图像保存到画廊。单击“保存”后,文件夹在图库中创建,但是当我进入图库时,它显示“没有缩略图”... 这是我的代码:
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);
}
});
【问题讨论】:
标签: android bitmap android-gallery android-bitmap