简体   繁体   English

用于tif缓冲图像的java中的setRgb丢失其坐标信息

[英]setRgb in java for tif buffered image loses its coordinate information

I have a program in java where tif file read in source buffered image and then this buffered image is replicated as destination buffered image. 我在Java中有一个程序,其中tif文件在源缓冲图像中读取,然后将该缓冲图像复制为目标缓冲图像。 When I write this buffered image on disk, the image loses its coordinate information. 当我将此缓冲的图像写入磁盘时,该图像会丢失其坐标信息。 What can be done so that coordinate information is not lost? 怎样做才能使坐标信息不丢失?

My code is: 我的代码是:

/* Check if imageType if tif */
if (imageType.equalsIgnoreCase(TIFF)) {
    bufferedImageType = BufferedImage.TYPE_INT_RGB;
}
BufferedImage destination = new BufferedImage(source.getWidth(), source.getHeight(),
                bufferedImageType);
/* Loop to cover all pixels */
for (int width = 0; width < source.getWidth(); width++) {
    /* Loop to cover all lines */
    for (int height = 0; height < source.getHeight(); height++) {
        destination.setRGB(width, height, source.getRGB(width, height));
    }
}
file = new File(TEMP_DIR + TEMP_FILE_NAME + "tif");
ImageIO.write(destination, "tif", file);

I know this post is old, but nevertheless... 我知道这篇文章很旧,但是...

If you are talking about all the header data that is lost during this process then you can use Apache Commons Imaging to copy the header from the source image file to the destination image file. 如果您正在讨论在此过程中丢失的所有标头数据,则可以使用Apache Commons Imaging将标头从源图像文件复制到目标图像文件。

Here is an example: 这是一个例子:

https://commons.apache.org/proper/commons-imaging/xref-test/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriteTest.html https://commons.apache.org/proper/commons-imaging/xref-test/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriteTest.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM