我有一个应用程序可以侦听设备上的新照片,调整它们的大小并上传到云端。
当我在他们之间使用小暂停进行拍照时(例如1秒)一切正常,但是当我快速拍摄照片时没有任何停顿< / strong>我有例外:
java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20180116_150824_1.jpg (No such file or directory)
在我的 compressAndResize 函数中。
在那个功能中,我做这样的事情:
private static File compressAndResizeImage(File sourceFile, File destination) throws IOException {
File compressedAssetFile = new File(destination, sourceFile.getName());
if (!compressedAssetFile.getParentFile().exists()) {
//noinspection ResultOfMethodCallIgnored
compressedAssetFile.getParentFile().mkdirs();
}
//noinspection ResultOfMethodCallIgnored
compressedAssetFile.getParentFile().createNewFile();
FileOutputStream fileOutputStream = null;
int width;
int height;
try {
fileOutputStream = new FileOutputStream(compressedAssetFile);
Bitmap source = BitmapFactory.decodeFile(sourceFile.getAbsolutePath());
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
...
在 BitmapFactory.decodeFile 方法中抛出异常。
当我快速拍照时,我不知道为什么会出现这种情况。
有人可以解释一下为什么会这样吗?
提前致谢!