使用iText在PDF文件中获取图像DPI [英] Getting Image DPI in PDF files using iText

查看:2035
本文介绍了使用iText在PDF文件中获取图像DPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过iText(使用Java)获取有关扫描图像的信息。

I 'm trying to get information about scanned images that are saved into PDF files through iText (using Java).

使用答案和评论,我得到了宽度和高度(通过Matrix或通过BufferedImage)。我的想法是在这里使用回答计算DPI,但我有点迷失。

Using the answer and comments, I got width and height (either through Matrix, or through BufferedImage). The idea was to use the answer here to calculate the DPI, but I am a bit lost.

这些值(宽度和高度)是以像素还是以点为单位?有没有其他方法来实现这一目标?关于如何将图像缩放并保存为PDF文件有很多答案,但我没有找到关于如何读取图像的宽度/高度/比例的任何答案,并对结果充满信心。

Are these values (width and height) in pixels or points? Is there any other way to achieve this? There are a lot of answers on how to scale and save an image to a PDF file, but I didn't find any on how to read the width/height/scale of an image and be confident about the result.

推荐答案

让我们将这个问题分成两个不同的问题。要计算DPI,您需要两组值:像素数和以英寸为单位的距离。

Let's split this problem into two separate problems. To calculate the DPI, you need two sets of values: a number of pixels and a distance in inch.


  1. 像素数:您获得图像和图像由像素组成。您可以从图像中检索图像的宽度和高度(以像素为单位)。假设这些值是 wPx wPx

  2. 以英寸为单位的距离:你得到的矩阵给你用点表示的值。当72点等于1英寸时,你需要将这些值除以72.假设这些值是 wInch hInch

  1. Number of pixels: you obtain the image and the image consists of pixels. You can retrieve the width and height of the image in pixels from the image. Let's say these values are wPx and wPx.
  2. Distance in inch: you obtain the matrix which gives you values expressed in points. As 72 points equal 1 inch, you need to divide these values by 72. Let's say these values are wInch and hInch.

现在你可以像这样计算x方向的DPI: wPx / wInch 和y方向的DPI如下: hPx / hInch

Now you can calculate the DPI in the x direction like this: wPx / wInch and the DPI in the y direction like this: hPx / hInch.

这篇关于使用iText在PDF文件中获取图像DPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆