簡體   English   中英

如何從Android中的YUV圖像文件獲取寬度和高度?

[英]How to get width and height from YUV image file in Android?

我正在創建一個簡單的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();
        }
    }
}

但是輸出是可怕的。 請參閱所附圖片。 在此處輸入圖片說明

我該如何解決這個問題?

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

試試這個鏈接,希望對您有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM