Write dpi metadata to a jpeg image in Java

后端 未结 2 1029
失恋的感觉
失恋的感觉 2020-12-10 03:05

I am trying to programatically set the dpi metadata of an jpeg image in Java. The source of the image is a scanner, so I get the horizontal/vertical resolution from TWAIN, a

相关标签:
2条回答
  • 2020-12-10 03:59

    I would seem this could be a bug.

    I found this post from a few google searches

    Apparently there are alot more that point to a bug as well.

    The post above talks about using JMagick as a third party work around.

    0 讨论(0)
  • 2020-12-10 04:03

    Some issues that were not considered here:

    1. The tree is not directly mapped to the IOMetaData. To apply data from tree, add following call after setting the densities and raster parameters:

      data.setFromTree("javax_imageio_jpeg_image_1.0", tree);
      
    2. don't use the meta data as first parameter in the write call. See JPEGImageWriter#write(IIOMetaData, IIOImage, ImageWriteParam). If streamMetaData is not NULL, a warning (WARNING_STREAM_METADATA_IGNORED) will be generated.

    3. set the meta data as IOMetadata of the IOImage. These meta data are used by JPEGImageWriter. The correct write call then is

      imageWriter.write(null, new IIOImage(F_scaledImg, null, data), jpegParams);
      
    0 讨论(0)
提交回复
热议问题