使用Java中的ImageIO编写TIFF的平铺输出 [英] Write tiled output of TIFF, using ImageIO in Java

查看:191
本文介绍了使用Java中的ImageIO编写TIFF的平铺输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所拥有的是大量的帧需要放在一个更大的图像(如马赛克)中。图像的所需位置是已知的。

What I have is a a large number of frames that need to be placed together in a larger image (like a mosaic). The required positions of the images are known.

图像数量非常大,因此将它们全部加载到内存中是不切实际的。

There are a very large number of images so loading them all into memory is impractical at best.

基于这里的一些其他答案,我能够覆盖RenderedImage中的方法(特别是 getData(rect))来加载适当的数据和返回它。

Based on some other answers here I was able to override the methods in RenderedImage (specifically getData(rect)) to load in the appropriate data and return it.

这很好用,但是图像编写器总是调用 getData 并请求数据行。在我看来,我应该能够改变ImageWriterParam来代替调用单个tile,但是当我尝试写入函数仍然需要从 getData 中调用一行。

This works just fine, however the image writer is always calling getData and requesting rows of data. It seems to me I should be able to change the ImageWriterParam to call for individual tiles instead, but when I tried the write function still calls for a single line from getData.

如何强制使用瓷砖并调用getTile。

How can I force this to use tiles and call getTile instead.

BufferedOutputStream bos=null;
try {
   bos = new BufferedOutputStream(new FileOutputStream(new File("test2.tiff")));

   ImageWriter writer =(ImageWriter) ImageIO.getImageWritersBySuffix("tif").next();

   ImageOutputStream ios=null

   ios = ImageIO.createImageOutputStream(bos); 

   writer.setOutput(ios);
   ImageWriteParam param = writer.getDefaultWriteParam();
   param.setTilingMode(ImageWriteParam.MODE_DEFAULT);

   RenderedImage mosaic = new MosaicImage(imageFiles[]);

   writer.write(null,new IIOImage(mosaic,null,null),param);

    } catch (FileNotFoundException ex) {

    }

注意我可以使用 param.setTilingMode(ImageWriteParam.MODE_EXPLICIT); setTiling(w,h,xoff,yoff);

然而,当使用它时, writer.write 仍然调用 getData( rect)在我的图片中,并且非常烦人地没有要求一个由<​​code> w,h 指定的大小的矩形。它调用一个大小不同的矩形(可能来自某些东西)

However when using this, writer.write still calls getData(rect) in my image, and very annoyingly does not call for a rectangle of the size specified by w,h. It calls a rectangle of a size that is different by some random amount(probably comes from something)

例如,如果我使用 setTiling(100,100, 0,0);

即使它不从图像中调用getTile,也可以预期传递给getData的Rectangle应该是( 0,0,100,100)但它传递矩形(0,0,96,96),它不是图像宽度的倍数或我能想到的任何其他东西。

one would expect that even if it does not call getTile from the image, the Rectangle passed to getData should be (0,0,100,100) but instead it passes Rectangle (0,0,96,96) which is not a multiple of the image width or anything else i can think of.

感谢您的帮助

推荐答案

如果您阅读了TileWidth和TileLength字段下的TIFF 6.0规范,您会发现文本

If you read up on the TIFF 6.0 spec under the TileWidth and TileLength fields, you will find the text


TileWidth必须是16的倍数。这种限制可以提高某些图形环境中的
性能,并增强兼容性
with压缩方案,如JPEG。

TileWidth must be a multiple of 16. This restriction improves performance in some graphics environments and enhances compatibility with compression schemes such as JPEG.

和TileLength类似。 100x100不能被16整除,但96x96是,我打赌是TIFF编码器尽力满足你的要求。

And similar for TileLength. 100x100 isn't divisible by 16, but 96x96 is, which I bet is the TIFF encoder trying its best to fullfill your request.

这篇关于使用Java中的ImageIO编写TIFF的平铺输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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