0

我正在创建一个简单的 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();
        }
    }
}

但是输出太可怕了。请参阅附图。 在此处输入图像描述

我该如何解决这个问题?

4

1 回答 1

0
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

试试这个链接希望这对你有帮助

于 2016-10-04T05:18:54.597 回答