2

I have a lot of small .png in a folder, and I want to join them together, the problem is that the final Buffered image is too big, resulting in an OutOfMemoryException (bigger than 32k x 32k);

Is there a way to create that image without having to inizialize a huge BufferedImage, but just, like, loading one small .png at a time, and appending it to another image on the disk, and so on, until the image is done?

If not, how to deal with this?

assylias
  • 321,522
  • 82
  • 660
  • 783
Dea5
  • 131
  • 1
  • 9
  • Show your code. Or look at JVM startup flags (`-Xmx`), – Axel Apr 24 '17 at 14:47
  • Consider [ImageMagick](https://www.imagemagick.org/script/index.php) and [im4java wrapper library](http://im4java.sourceforge.net/) to call ImageMagick functions from java. –  Apr 24 '17 at 14:50
  • Being clever and pairing the images, merging 2 at a time, and then 2 products of the first round and so on... have a look at this answer to help you with step 1: http://stackoverflow.com/questions/3922276/how-to-combine-multiple-pngs-into-one-big-png-file – diginoise Apr 24 '17 at 15:10
  • @diginoise that's how I'm actually dealing with this, the problem is that my final BufferedImage is too big. – Dea5 Apr 24 '17 at 15:29
  • how much memory do you give this process? – diginoise Apr 24 '17 at 15:30
  • With 6GB of allocated memory I'm able to create a 32000x32000 .png image, but the point is that I want a "generic" way to deal with this (Creating an image as big as I want), where, "ideally", the only limit will be my disk memory. – Dea5 Apr 24 '17 at 15:37
  • Perhaps PNG-specific operations will help like here http://stackoverflow.com/a/6176487/798021 – arataj Apr 24 '17 at 19:55

1 Answers1

0

You can try PNGJ, which lets you read and write PNG images line by line.

In Snippets there is an example (Image tiling) that puts together several images of the same size.

leonbloy
  • 73,180
  • 20
  • 142
  • 190