0

私は以下の機能を使用しています

public void renderImage(ImageRenderInfo renderInfo) {
    try {
        String filename;
        FileOutputStream os;
        PdfImageObject image = renderInfo.getImage();


        PdfDictionary imageDict = renderInfo.getImage().getDictionary();
        float widthPx = imageDict.getAsNumber(PdfName.WIDTH).floatValue(); 
        float heightPx = imageDict.getAsNumber(PdfName.HEIGHT).floatValue();
        float widthUu = renderInfo.getImageCTM().get(Matrix.I11);
        float heigthUu = renderInfo.getImageCTM().get(Matrix.I22);

 //while printing in inches I am dividing heightUu and widthUu by 72

        System.out.printf("Image %.0fpx*%.0fpx, %.0fuu*%.0fuu, %.2fin*%.2fin\n", widthPx, heightPx, widthUu, heigthUu, widthUu/72, heigthUu/72);

        if (image == null) return;
        filename = String.format(path, renderInfo.getRef().getNumber(), image.getFileType());
        System.out.println(filename);
        os = new FileOutputStream(filename);
        os.write(image.getImageAsBytes());
        os.flush();
        os.close();


    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
}

フォトショップで画像サイズを確認すると、高さと幅がピクセル単位で完全に取得されますが、幅と高さがインチ単位で正しく取得されません

画像の DPI を計算できるようにするために必要です。

例:

画像の元の値: 幅 - 450 ピクセル、高さ - 362 ピクセル

幅 - 6.25 インチ、高さ - 5.028 インチ (Photoshop から取得した値)

私がitextから受け取るもの:

幅 - 450 ピクセル、高さ - 362 ピクセル (これで完璧です)

幅 -3.60 インチ、高さ - 2.90 インチ (ここに問題があります)

4

0 に答える 0