java - Pie 上的 Camera2 API 越界异常

标签 java android android-camera2 android-9.0-pie

我正在使用 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) 设备上运行。

这是 list 文件代码

<?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

关于java - Pie 上的 Camera2 API 越界异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59290892/

相关文章:

java - 在android中循环内更改imageview图像

java - 使用 toString 方法但组合框仍然不显示值

java - Eclipse E4 RCP 全局错误处理

android - 这个 Handler 类应该是静态的,否则可能会发生泄漏

android - 黑客新闻Android客户端: "Cannot resolve symbol ' MainActivity _'"

android - 对象在应用程序相机的边缘显得模糊

java - 扫描 HBase 中的复合键

android - 位图的大小和方向不正确

android - 为什么 camera2 支持的预览尺寸宽度总是大于高度?

android - 版本代码/版本名称错误