Compressor
Compressor copied to clipboard
ExifInterface got an unsupported image
My version : 2.1.0
my function:
public File compressImage(String path, int width, int height, int quality) {
try {
return new Compressor(MyApplication.getContext())
.setMaxWidth(width)
.setMaxHeight(height)
.setQuality(quality)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.compressToFile(new File(path), " " + System.currentTimeMillis());
} catch (IOException e) {
Mylog.printStackTrace(TAG + " compressImage error path : " + path, e);
return null;
}
}
stacktrace:
W/ExifInterface: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
java.io.IOException: Invalid marker: 89
at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1835)
at android.media.ExifInterface.loadAttributes(ExifInterface.java:1475)
at android.media.ExifInterface.<init>(ExifInterface.java:1112)
at id.zelory.compressor.ImageUtil.decodeSampledBitmapFromFile(ImageUtil.java:60)
at id.zelory.compressor.ImageUtil.compressImage(ImageUtil.java:33)
at id.zelory.compressor.Compressor.compressToFile(Compressor.java:60)
I get the same error.
The ExifInterface may has this bug. and then I find the ExifInterface used in ImageUtil.decodeSampledBitmapFromFile#44
,
It's only used for get image orientation, but it should not directly throw an exception to user. I mean it will just post an error log to console, can not make the compress failed .
Because your lib's main work is Compress file, is it?
The code may be like this.
Matrix matrix = new Matrix();
try {
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
if (orientation == 6) {
matrix.postRotate(90);
} else if (orientation == 3) {
matrix.postRotate(180);
} else if (orientation == 8) {
matrix.postRotate(270);
}
} catch(IOException ex) {
ex.printStackTrace();
}
Thank you. @mrhuo is it running before compression?
yes, png file will make this error, error message is: Invalid marker: 89.
maybe Exif tag only worked for jpg file
see this link
https://stackoverflow.com/questions/40066054/exifinterface-constructor-throws-ioexxception
I am also getting same exception on Android 10
W/ExifInterface: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
java.io.IOException: Invalid byte order: ffff8950
at android.media.ExifInterface.readByteOrder(ExifInterface.java:3128)
at android.media.ExifInterface.isOrfFormat(ExifInterface.java:2443)
at android.media.ExifInterface.getMimeType(ExifInterface.java:2321)
at android.media.ExifInterface.loadAttributes(ExifInterface.java:1755)
at android.media.ExifInterface.initForFilename(ExifInterface.java:2303)
at android.media.ExifInterface.<init>(ExifInterface.java:1386)
at id.zelory.compressor.UtilKt.determineImageRotation(Util.kt:70)
at id.zelory.compressor.UtilKt.loadBitmap(Util.kt:34)
at id.zelory.compressor.constraint.QualityConstraint.satisfy(QualityConstraint.kt:21)
at id.zelory.compressor.Compressor$compress$3.invokeSuspend(Compressor.kt:28)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:740)
我的方式
1. compileOnly "androidx.exifinterface:exifinterface:1.3.2"
2. replace `android.media.ExifInterface` with `androidx.exifinterface.media.ExifInterface`
不工作兄弟