Camera2 API超出Pie的边界限制

问题描述 投票:0回答:1

我正在使用sdk来处理使用camer2 api的图像,但是它无法在android Pie(28)设备上正常工作,并且无法在早期版本上正常工作。它会自动关闭相机,有时会在代码中以下标记的行上抛出界外异常:

 class CWorker
  {
    /**
     * Set the current capture to evaluate.
     * @param argImage The capture to evaluate.
     */
    void setCurrentCapture ( final Image argImage )
    {
      // copy the image planes to the byte array then the array to the YUV allocation
      final ByteBuffer objImageBufferY = argImage.getPlanes ()[ 0 ].getBuffer ();
      final ByteBuffer objImageBufferU = argImage.getPlanes ()[ 1 ].getBuffer ();
      final ByteBuffer objImageBufferV = argImage.getPlanes ()[ 2 ].getBuffer ();
      final int iBufferYSize = objImageBufferY.remaining ();
      final int iBufferUSize = objImageBufferU.remaining ();
      final int iBufferVSize = objImageBufferV.remaining ();
      objImageBufferY.get ( m_xbYuvBuffer, 0, iBufferYSize );
      objImageBufferV.get ( m_xbYuvBuffer, iBufferYSize, iBufferVSize );
     ****objImageBufferU.get ( m_xbYuvBuffer, iBufferYSize + iBufferVSize, iBufferUSize );****
      m_objRenderscriptMemYuv.copy1DRangeFromUnchecked ( 0, iBufferYSize + iBufferVSize + iBufferUSize, m_xbYuvBuffer );
    }
}

我不知道为什么它不能在Android Pie(28)设备上运行。

这里是清单文件代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.xxx.xxx">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera2" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera2.autofocus" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:networkSecurityConfig="@xml/network_security_config"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name="com.xxx.xxx.xxx.activities.DashboardActivity"
            android:label=""
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />
      <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.xxx.xxx.xxx.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider" />
        </provider>
    </application>

</manifest>
java android android-camera2 android-9.0-pie
1个回答
0
投票

将最小sdk 15目标sdk更改为29,将sdk更改为29

© www.soinside.com 2019 - 2024. All rights reserved.