【问题标题】:Camera SetPreviewCallback best way to convert YUV to RGBCamera SetPreviewCallback 将 YUV 转换为 RGB 的最佳方法
【发布时间】:2012-09-30 22:01:03
【问题描述】:

在调用camera.takePicture 之后,我正在使用此代码将图像写入SD:

protected String doInBackground(byte[]... jpeg) {
    File directory=new File(Environment.getExternalStorageDirectory() + "/" + getString(R.string.qpw_picture_path) + "/" + getString(R.string.qpw_picture_title) + "_" + initialTime);
    directory.mkdirs();
    String currentTime = new SimpleDateFormat(getString(R.string.qpw_date_format)).format(new Date());
    File photo = new File (directory, getString(R.string.qpw_picture_title) + "_" + currentTime + "_" + current + ".jpg");
    current++;

    if (photo.exists()) {
        photo.delete();
    }

    try {
        FileOutputStream fos=new FileOutputStream(photo.getPath());         
        fos.write(jpeg[0]);
        fos.flush();
        fos.close();
    }
    catch (java.io.IOException e) {
    }

    new ImageMediaScanner(getBaseContext(), photo);
    return(null);
}

在这种情况下工作正常,但是当我使用相同的代码从 camera.setPreviewCallback 写入图像时,我最终会在 SD 上得到 450KB 损坏的图像,这些图像无法使用甚至无法打开。

任何帮助或建议将不胜感激。

编辑:

看来数据应该先从YUV转RGB再保存。尝试了在 Google 和 SO 上找到的众多代码示例之一,我没有遇到更多问题。

有谁知道最好的方法是什么?在速度、内存分配、CPU...

【问题讨论】:

    标签: android android-camera rgb


    【解决方案1】:

    以防万一有人偶然发现同样的问题this SO post 总结一下我在寻找什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      相关资源
      最近更新 更多