1
我有一個圖像保存在android.When我按保存按鈕,然後圖像(.jpg)實際上保存在外部存儲。但概率是,它並沒有在我的畫廊展示immediately.It顯示數小時後MAYB,天哦,多麼o不可... 保存下我使用下面的代碼:保存圖像文件在外部存儲工程buts圖像沒有顯示在圖庫中立即
if (item.getItemId() == R.id.item3) {
String root = Environment.getExternalStorageDirectory().toString();
myDir = new File(root + "/PaintImage");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-" + n + ".jpg";
file = new File(myDir, fname);
if (file.exists())
file.delete();
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
Toast.makeText(getApplicationContext(), file.getAbsolutePath(),
Toast.LENGTH_LONG).show();
try {
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
文件夾獲取創建SD卡,但保存圖像時,Gallery不會立即顯示。
謝謝你提前幫忙。
有你所使用的介質掃描儀更新畫廊 – Dilip
人無我有使用媒體掃描儀 –
你應該使用媒體掃描儀作爲克里斯蒂曾建議辦理鏈接並閱讀文檔 – Dilip