我希望将位图保存到缓存目录。我使用以下代码:
我该怎么修复它?提前感谢您。
try {
File file_d = new File(dir+"screenshot.jpg");
@SuppressWarnings("unused")
boolean deleted = file_d.delete();
} catch (Exception e) {
// TODO: handle exception
}
imagePath = new File(dir+"screenshot.jpg");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
它正常运行。但是如果我想将不同的图片保存到相同的路径,就会出现问题。我的意思是它保存到了相同的路径,但我看到的是旧图片,但当我点击图片时,我可以看到我第二次保存的正确图片。
可能是缓存导致的,但我不想看到旧图片,因为当我想通过WhatsApp共享该图片时,会显示旧图片,但是如果我发送图片,则显示正确的图片。
我想像这个代码一样分享保存的图片到 WhatsApp:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imagePath));
shareIntent.setType("image/jpeg");
startActivityForResult(Intent.createChooser(shareIntent, getResources().getText(R.string.title_share)),whtsapp_result);
我该怎么修复它?提前感谢您。
deleted
值。如果图片被删除,则永远不会回来。 - Zahidul Islam