search

Home  >  Q&A  >  body text

sanselan - java技术读取图片的分辨率值,单位为dpi

最近项目需要,对上传的图片需要获取并判断它的dpi值是否合格。右键单击图片,查看其属性,点击详细信息,可以看到图片的长宽(像素),以及水平、垂直分辨率(dpi),当然这种方式仅限于jpg图片,其他格式的图片可以使用ps查看。

从网上查了很多资料,很多人对分辨率的理解就是图片的长宽,我不是专门研究图片的,所以概念上不作辩论,但图片属性和ps显示的分辨率值单位均为dpi,长宽是另外的。

我在网上找到个apache的开源类——Sanselan(sanselan-0.97-incubator.jar),用简单的java代码试了一下,可以准确地读到dpi值,用了一个ImageInfo类,我用的InputStream实例化的ImageInfo。可以用到Uedit上传图片时,用Uedit提供的图片输入流实例化ImageInfo类,对上传的合格图片,有的dpi值读到却是-1,就是失败了,希望有使用Sanselan经验的人指点迷津。

大家讲道理大家讲道理2804 days ago1218

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 11:33:44

    The question I raised has been verified.

    1. The Ueditor rich text editor will modify the uploaded images. What I encountered was that it changed the png image to a jpg image, and the size, length and width of the image also changed. But not all uploaded images will be converted. Ueditor has a threshold. If you increase this value, the images will not change.
    2. Sanselan, an open source jar package, is now renamed Imaging. Looking at the official documentation, you can find that this open source component does not support all images. Certain formats of images only support certain specifications, so the dpi value read for some images downloaded from the Internet is -1. This can only prompt the user to use ps software to process the image or save it as a file, and then upload it to read the dpi value.

    reply
    0
  • Cancelreply