5

In my eclipse-rcp application I need to create an image with dimensions 30000x10000 px or more. This image is NatTable representation. Using standard image creation approach, it fails with different problems: OutOfMemory, SWTError - IllegalArgument or my PC stops responding (btw, its windows 7, 64bit, 4 RAM - client have much slower laptops, but the picture is still needs to be created). Here is a code snippet:

private Image getNattableImageRepresentation(final Display display) {
        final Rectangle totalGridArea = getTotalGridArea(); //this returns Rectangle(0,0,30000,10000)
        setGridLayerSize(totalGridArea);
        final Image nattableImage = new Image(display, totalGridArea);
        final GC nattableGC = new GC(nattableImage);
        gridLayer.getLayerPainter().paintLayer(gridLayer, nattableGC, 0, 0, totalGridArea, configRegistry);//nattable API, which draws an image into a specified gc
        restoreGridLayerState();
        return nattableImage;
    }
    return null;
}

Are there any tricks to create such huge images or may be API? Is Java Advanced Imaging Api suitable for this purpose?

Any suggestions are appreciated.

Alex K.
  • 3,294
  • 4
  • 29
  • 41
  • So you want to save your table to image file..? – Sorceror Feb 03 '12 at 10:20
  • This article always helped me when I was looking on some image problems - [SWT image resources](http://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html) – Sorceror Feb 03 '12 at 10:21
  • Thank you for the article, I will definitely take a look at it. No, I don't need to save the table into the file, I actually need to get an ImageData object to be able to print NatTable using PaperClips ImagePrint. Sa basically, I need to print the table. – Alex K. Feb 03 '12 at 10:46
  • So workaround might be to "snap" grid of images into more smaller images and then "join" them by some command line utility ;].. – Sorceror Feb 03 '12 at 12:25
  • Yes, I've started to implement it, but I tried to join those parts into one image by using new GC and drawImage method - it still failed with OutOfMemory (I've tried -Xmx1024m). What command line utility do you have in mind (if any)? And still....may be there is more better solution, then splitting an image (cause a lot of printing-related problems will occur, if I have multiple ImageData-s? – Alex K. Feb 03 '12 at 12:46
  • 2
    [ImageMagick](http://www.imagemagick.org/script/montage.php?ImageMagick=6gtf7marm2do5071dhvlln8lr2) is neat tool for image processing like this.. new CG is not the way, definitely.. What printing-related problems you have in mind..? If you'll join all spare images to the big one, there should be no problem at all.. – Sorceror Feb 03 '12 at 13:43
  • Well, PaperClips has ImagePrint, which takes ImageData as an argument. If I create multiple images and thus multiple ImagePrints and then create SeriesPrint with those ImagePrints, each new print will start on the new page and thus will have a gap, which is not acceptable. If I'll try to cut image to such pieces, which are fully taking page width, it will cause problems with different paper sizes and orientations. But I hope, the tool you have suggested will make my day:) Fortunately, I will be able to load this huge composed image afterwards. – Alex K. Feb 03 '12 at 15:47
  • There are also tools that will [print the whole image borderless](http://www.blockposters.com/), but it's not an Java API.. – Sorceror Feb 03 '12 at 18:17
  • Thank you, but I doubt it can be useful in my case. I even took a closer look to the ImagiMagic and think it can't be used. First of all, its 16Gb and its OS-specific, there is no way we can provide it for all our application installations( Such a pity, that Java can not handle those big drawings.. – Alex K. Feb 05 '12 at 10:46
  • And [JAI](http://java.sun.com/javase/technologies/desktop/media/) would not help you..? – Sorceror Feb 06 '12 at 12:29
  • JAI, might be an option)) That's why I've mentioned it in my question, I've made quick investigation and could not find any tutorial about composing images. But actually, I've now talked to the PM and it seems, that it is okay to use ImageMagic, so I will stuck to this at the moment. You could post it as an answer, so that I can accept it. Tank you for you help! – Alex K. Feb 06 '12 at 12:38
  • Possible duplicate of [Why does a BufferedImage require so much memory beyond the size of its data array?](https://stackoverflow.com/questions/3854200/why-does-a-bufferedimage-require-so-much-memory-beyond-the-size-of-its-data-arra) – JHead Nov 08 '18 at 10:24

2 Answers2

1

ImageMagick is neat tool for image processing like this.. new CG is not the way, definitely.. If you'll join all spare images to the big one, there should be no problem at all..

Sorceror
  • 4,835
  • 2
  • 21
  • 35
  • 1
    Composing is working as expected, but seems, that it consumes quite a lot of memory. I've tried im4java interface for ImageMagick, but it should not be a reason. And when composed image is loaded back into the application, Java still can not handle it. The image is only 10Mb (15000x400), but it fails with SWT errors, this is sad. – Alex K. Feb 06 '12 at 16:39
  • 1
    It's definitely not just 10MB (it is, but compressed), you got 15000x400 = 6M pixels per 32-bits, but there is huge overhead on each image, especially when SWT use some platform dependent handles.. But you're right, it's sad anyway.. – Sorceror Feb 06 '12 at 17:49
0

There is a simple solution for storing larger images in Java. BigBufferedImage stores the image on the hard drive in a very fast way:

https://stackoverflow.com/a/53205617/2631710

JHead
  • 356
  • 2
  • 12