I am going to compress the image using the method Bitmap.compress().
But when I get Bitmapusing bitmap = BitmapFactory.decodeFile(), I get the object null, and this method did not rule out any exceptions.
Here is my code
public static File compressImage(String imagePath) throws IOException {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
......
When the code runs on the last line, I get a NullPointerException:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
Then I run my code in debug mode, it turned out that I have an object nullfrom the method BitmapFactory.decodeFile.
The parameter imagePathis
/storage/emulated/0/DCIM/Camera/IMG_20160610_195633.jpg
which looks ok.
, , , . - , ? - ?