Java 饼图上的Camera2 API越界异常

Java 饼图上的Camera2 API越界异常,java,android,android-camera2,android-9.0-pie,Java,Android,Android Camera2,Android 9.0 Pie,我正在使用sdk来处理使用Camer2API的图像,但它不能在android Pie(28)设备上正常工作,也不能在早期版本上正常工作。它会自动关闭摄像头,有时会在代码中下面标记的行上抛出越界异常: class CWorker { /** * Set the current capture to evaluate. * @param argImage The capture to evaluate. */ void setCurrentCapt

我正在使用sdk来处理使用Camer2API的图像,但它不能在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>


将最小sdk 15目标sdk更改为29编译sdk更改为29

将最小sdk 15目标sdk更改为29编译sdk更改为29–谢谢@sashabelly,我尝试了您的解决方案。将sdk版本更改为29后,现在它正在打开摄像头,但图像未捕获。您是否授予其他应用访问摄像头的权限?我只有一个应用使用OCR sdk。它在饼前设备上运行良好有时我收到一条异常消息“最大值(2)已经获得,在获得更多之前,请调用#close。”