【问题标题】:How to get width and height from YUV image file in Android?如何从 Android 中的 YUV 图像文件中获取宽度和高度?
【发布时间】:2016-10-04 05:12:53
【问题描述】:

我正在创建一个简单的 YUV 到 JPEG 图像转换器。为此我需要从文件中获取 YUV 图像的大小。我在这里硬线测试。但我需要从语法上获取这些细节。任何帮助将不胜感激。

private void covertToYuvImage() {

    ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
    String yuvImagePath = selectedFolder+yuvImageList.get(0); //Path to YUV image
    File file = new File(yuvImagePath);
    byte[] bFile = new byte[(int) file.length()];
    try{
        FileInputStream fileInputStream = new FileInputStream(file);
        fileInputStream.read(bFile);
        fileInputStream.close();
    }
    catch (Exception e){
        e.printStackTrace();
    }

    YuvImage yuvImage = new YuvImage(bFile, ImageFormat.NV21,2048,1536,null);
    yuvImage.compressToJpeg( new Rect(0, 0, 2048, 1536), 100, baoStream);

    File imgFile = new File(selectedFolder, "NewImage.jpeg");
    if (!imgFile.exists()) {

        FileOutputStream img;
        try {
            img = new FileOutputStream(imgFile);
            img.write(baoStream.toByteArray());
            img.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

但是输出很糟糕。请看附图。

我该如何解决这个问题?

【问题讨论】:

标签: android android-camera fileinputstream yuv image-formats


【解决方案1】:
YuvImage yuvImage = new YuvImage(bFile, ImageFormat.NV21,2048,1536,null);
yuvImage.compressToJpeg( new Rect(0, 0, 2048, 1536), 100, baoStream);
yuvImage.getWidth () // it will return width in int
yuvImagegetHeight() // It will return height in int

Try this link希望对你有帮助

【讨论】:

  • 这将返回 2048 和 1536.. 但我想知道是否可以从 YUV 图像文件中获取这些值,这些值可以在 YuvImage 的构造函数中使用
  • 你对输出图像有什么想法吗
  • 希望这个链接能帮到你stackoverflow.com/questions/9192982/…
猜你喜欢
  • 1970-01-01
  • 2010-11-07
  • 1970-01-01
  • 2011-06-08
  • 1970-01-01
  • 2019-05-20
  • 2015-02-09
  • 2013-05-02
  • 1970-01-01
相关资源
最近更新 更多