gpt4 book ai didi

使用 ExifInterface 时出现 Android 错误

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:31:23 27 4
gpt4 key购买 nike

我正在尝试检查位图的方向并在需要时翻转它,但在应用代码时出现错误。这是我尝试使用 ExifInterface 翻转图像时的代码:

@RequiresApi(api = Build.VERSION_CODES.N)
public void flipping(Bitmap b)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG,100, bos);
byte[] bitmapdata = bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
try {

ExifInterface exif = new ExifInterface(bs);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
switch(orientation) {

case ExifInterface.ORIENTATION_ROTATE_90:
rotateImage(b, 90);
break;

case ExifInterface.ORIENTATION_ROTATE_180:
rotateImage(b, 180);
break;

case ExifInterface.ORIENTATION_ROTATE_270:
rotateImage(b, 270);
break;

case ExifInterface.ORIENTATION_NORMAL:

default:
break;
}

encoding();
} catch (IOException e) {
e.printStackTrace();
}
}
public static Bitmap rotateImage(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
matrix, true);
}

这里是错误:

java.lang.NoSuchMethodError: No direct method <init>(Ljava/io/InputStream;)V in class Landroid/media/ExifInterface; or its super classes (declaration of 'android.media.ExifInterface' appears in /system/framework/framework.jar)
at com.sara.image_test.MainActivity.flipping(MainActivity.java:181)
at com.sara.image_test.MainActivity.onActivityResult(MainActivity.java:66)
at android.app.Activity.dispatchActivityResult(Activity.java:7165)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4994)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5041)
at android.app.ActivityThread.access$1600(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

最佳答案

AndroidX使用

androidx.exifinterface.media.ExifInterface

build.gradle中引入这个依赖:

implementation 'androidx.exifinterface:exifinterface:1.3.2'

关于使用 ExifInterface 时出现 Android 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44246110/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com