Compressor icon indicating copy to clipboard operation
Compressor copied to clipboard

ExifInterface got an unsupported image

Open gelbertgel opened this issue 6 years ago • 6 comments

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)

gelbertgel avatar Jun 08 '18 14:06 gelbertgel

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();
}

mrhuo avatar Jul 30 '18 04:07 mrhuo

Thank you. @mrhuo is it running before compression?

gelbertgel avatar Jul 31 '18 06:07 gelbertgel

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

mrhuo avatar Aug 01 '18 18:08 mrhuo

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)

aniruddhha avatar Jun 10 '20 14:06 aniruddhha

我的方式

1.    compileOnly "androidx.exifinterface:exifinterface:1.3.2"
2.    replace `android.media.ExifInterface` with `androidx.exifinterface.media.ExifInterface`

javakam avatar Dec 10 '20 08:12 javakam

不工作兄弟

Mohsents avatar Aug 15 '21 13:08 Mohsents