我有一个使用ImageView
和包含不同图像的应用程序ViewPager
。我想保存通过ImageView
中显示的当前图像SD Storage
。但它总是Phone Storage
成功保存。我想保存图像SD Card
并且保存的图像没有显示在Gallery
为什么?请帮助我解决这个问题:
public void SaveIamge() {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Cute_Baby_Images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
int currentImagePos = viewPager.getCurrentItem();
Drawable drawable = viewPager.getResources().getDrawable(images[currentImagePos]);
Bitmap finalBitmap = ((BitmapDrawable) drawable).getBitmap();
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(this, "Sucessfully Save Image", Toast.LENGTH_LONG).show();
}