如何在java中从多个图块创建一个大图像文件?

发布于 2024-09-13 03:34:16 字数 346 浏览 1 评论 0原文

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

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

我正在寻找一种不使用 JAI 来执行此操作的方法(无法从公共 Maven 存储库安装,我不明白为什么)

有没有办法使用纯 java2D 来执行此操作?或者是否存在另一个库能够处理这个问题?

我最初的想法是创建一个非常大的缓冲图像,从备份到磁盘上的文件的数据缓冲区。但我不确定这是否可能。有人这样做过吗?

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

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.

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)

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

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

溇涏 2024-09-20 03:34:16

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

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

我最初的想法是创建一个非常大的缓冲图像,从备份到磁盘上的文件的数据缓冲区。但我不确定这是否可能。有人这样做过吗?

是的,我已经写了一个不完整的实现。它由一个由 ByteBuffer 支持的 DataBuffer 组成

  • ,而不是一个数组(如果缓冲区是直接的,它可以映射到一个文件。)
  • 一个 WritableRaster< /code> 与标准栅格类似,但使用我的 DataBuffer 实现(JDK 中的标准栅格通过保存对后备数组的引用来作弊。在直接 的情况下没有数组>ByteBuffer 所以不幸的是你必须重新实现大多数 Raster 方法。)

我不建议扩展 SampleModel 因为你的类不能与 JDK 栅格一起工作(各种Java2D 中的方法(包括 Raster 工厂方法)会打开 SampleModel 的类型,假设它是标准类型之一,恕我直言,但您对此无能为力。遵循相同的模式。)

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.

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.

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 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.)

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.)

人生戏 2024-09-20 03:34:16

我不知道是否可以不将所有内容加载到内存中。您可以将所有图像转储为未压缩的 bmp,然后使用一些外部工具将其转换为 jpg。

I don't know if it is possible without loading everything into memory. You can dump all your images to an uncompressed bmp, and then use some external tool to convert it to jpg.

删除会话 2024-09-20 03:34:16

如果您在使用公共 Maven 存储库中的资源时遇到问题,您可能需要使用 Nexus,一个 Maven 代理,并在那里手动添加 JAI jar(并将其添加到您的存储库列表中)。

选择此解决方案的优点是您将拥有 JAI,并且将拥有以 Maven 方式使用非 Maven 资源(所有 javax 库)的标准方法。

不要在自己周围摆弄这个,由于涉及所有压缩,并且在磁盘上处理 BMP 时,成像问题很复杂,考虑到您的图像大小(大约 100 * 30MB = 3GB)可能不是最佳的也不是快速的。

If you have trouble using a resource from a public maven repository you might want to use Nexus, a maven proxy, and manually add the JAI jar there (and add that to your list of repositories).

The advantage of chosing this solution is that you would have JAI, and would have a standard way to use non-maven resources (all the javax libraries) in a maven way.

Don't fiddle with this around yourself, the imaging matter is complex due to all the compression involved and dealing with BMPs on disk is, given your image sizes (about 100 * 30MB = 3GB) probably not optimal nor fast.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文