当我运行Android应用程序时出现错误。我正在使用以下代码来压缩图像并上传到Firebase。请帮助我解决问题。任何其他方法都可以,然后请告诉我该方法
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 507 && resultCode == RESULT_OK && data != null && data.getData() != null) {
ImageUri = data.getData();
File actualImage = new File(ImageUri.getPath());
File imgFile = new File(actualImage.getAbsolutePath());
if (!imgFile.exists())
{
try {
imgFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Log.e("actual_image", String.valueOf(imgFile));
try {
Bitmap compressedImage = new Compressor(this)
.setMaxWidth(300)
.setMaxHeight(250)
.setQuality(50)
.compressToBitmap(imgFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
compressedImage.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] final_image = baos.toByteArray();
Log.e("Final_image", String.valueOf(final_image));
} catch (IOException e) {
e.printStackTrace();
Log.e("Error_image", String.valueOf(e));
}
}
}
E / Error_image:java.io.FileNotFoundException:/raw/storage/1693-44A7/DCIM/Camera/IMG_20190525_080405.jpg(无此类文件或目录)