【问题标题】:how to get RGB values from byte[] array in android camera2 when ImageFormat is JPEG?当ImageFormat为JPEG时,如何从android camera2中的byte []数组获取RGB值?
【发布时间】:2016-03-12 19:08:30
【问题描述】:

我正在使用 camera2 API 我有兴趣从字节数组中获取 RGB 值实际上是 RGB 值的平均值当从 ByteBuffer 收集字节数组并使用 FileOutputStream.write(bytes )

这是我的代码:

ByteBuffer byteBuffer = mImage.getPlanes()[0].getBuffer(); byte[] bytes = new byte[byteBuffer.remaining()]; byteBuffer.get(bytes); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(mImageFile); fileOutputStream.write(bytes); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { mImage.close(); try { fileOutputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

【问题讨论】:

    标签: android camera2


    【解决方案1】:

    Image 类参考页面暗示 this BitmapFactory method 可能是您正在寻找的,用于将 JPEG 格式数据转换为 Bitmap

    但是,如果您也不需要将数据以 JPEG 格式保存到文件中(即,如果您只是在应用程序中处理来自相机的图像),您可能需要考虑更改输出Surface 格式从 JPEGYUV_420_888。然后,您可以将其转换为 RGB Bitmap(请参阅 this answer)并节省编码 JPEG 所需的大量时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-11
      • 2016-04-30
      • 2011-05-16
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多