【问题标题】:Camera2 API Out of Bound exception on PiePie上的Camera2 API超出范围异常
【发布时间】:2019-12-11 17:15:32
【问题描述】:

我正在使用 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>

【问题讨论】:

  • 更改最小 sdk 15 目标 sdk 到 29 编译 sdk 到 29¨

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


【解决方案1】:

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

【讨论】:

  • 谢谢@sashabelly,我试试你的解决方案。
  • 将sdk版本改为29后,现在正在打开摄像头,但无法捕捉图像
  • 您是否授予其他应用访问相机的权限
  • 我只有一个使用 OCR sdk 的应用程序。它在 PIE 之前的设备上运行良好
  • 有时我会在异常“maxImages (2) 已获取,在获取更多之前调用#close。”中收到此消息。
猜你喜欢
  • 2014-11-12
  • 2014-03-06
  • 2011-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多