如何从java中的许多tile创建一个大图像文件? [英] How to create a big image file from many tiles in java?

查看:104
本文介绍了如何从java中的许多tile创建一个大图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序生成10 x 10个图像,每个像素为3000x3000像素(目前保存到100个名为 image_x_y.jpg 的文件)

My program produces 10 x 10 tiles images of 3000x3000 pixel, one by one (currently saved to 100 files named image_x_y.jpg)

我想将这100个图像组合成一个大图像,而不是将所有内容都加载到内存中。我的目标是创建一个30'000 * 30'000像素的大图像文件。

I want to assemble these 100 images into one big image, without loading everything in memory. My goal is to create one big image file, of 30'000 * 30'000 pixels.

我正在寻找一种方法来做到这一点没有使用JAI(不能从公共maven存储库安装,我不明白为什么)

I'm looking for a way to do this without using JAI (which cannot be installed from public maven repositories, I don't understand why)

有没有办法用纯java2D做到这一点?或者是否存在其他库,能够处理这个吗?

Is there a way to do this with pure java2D ? Or does another library exist, able to handle this ?

我最初的想法是从支持磁盘上文件的DataBuffer创建一个非常大的缓冲图像。但我不确定这是可能的。有没有人这样做过?

My original idea was to create a very big buffered image, from a DataBuffer backed to a file on the disk. But i'm not sure that this is possible. Did anybody ever do this ?

推荐答案


我想将这100幅图像组合成一个大图像,不加载内存中的所有内容。我的目标是创建一个30'000 * 30'000像素的大图像文件。

I want to assemble these 100 images into one big image, without loading everything in memory. My goal is to create one big image file, of 30'000 * 30'000 pixels.

我相信有一个类JAI这样做。无论您将JAI集成到项目中遇到什么问题,我都会坚持不懈而不是推出自己的版本。在Java2D中没有这样的东西。

I believe there is a class in JAI that does this. Whatever problems you are having with integrating JAI into your project I would persevere with that rather than roll your own version. There is nothing like this in Java2D.


我最初的想法是创建一个非常大的缓冲图像,从支持DataBuffer的文件开始磁盘。但我不确定这是可能的。有没有人这样做过?

My original idea was to create a very big buffered image, from a DataBuffer backed to a file on the disk. But i'm not sure that this is possible. Did anybody ever do this ?

是的我写了一个不完整的实现。它包含

Yes I have written an incomplete implementation of this. It consists of


  • A DataBuffer ByteBuffer 而不是数组(如果缓冲区是直接的,它可以映射到文件。)

  • A WritableRaster 类似于标准栅格,但使用我的 DataBuffer 的实现(JDK作弊中的标准栅格,通过保持对后备数组的引用。没有数组在直接 ByteBuffer 的情况,所以不幸的是你必须重新实现大多数 Raster 方法。)

  • A DataBuffer that is backed by a ByteBuffer instead of an array (if the buffer is direct it can be mapped to a file.)
  • A WritableRaster similar to the standard rasters but using my implementation of DataBuffer (the standard rasters in the JDK cheat by holding a reference to the backing array. There is no array in the case of a direct ByteBuffer so unfortunately you must re-implement most Raster methods.)

我不建议扩展 SampleModel ,因为你的类不适用于JDK栅格(各种方法在Java2D包括 Raster 工厂方法切换 SampleModel 的类型,假设它是标准的类型之一。恕我直言,但除了遵循相同的模式,你可以做很多事情。)

I do not recommend extending SampleModel because your class will not work with the JDK rasters (various methods in Java2D including the Raster factory methods switch on the type of the SampleModel assuming it is one of the standard ones. Bad design IMHO but not much you can do about it except follow the same pattern.)

这篇关于如何从java中的许多tile创建一个大图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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