How to create a large SWT image?

In my eclipse-rcp application, I need to create an image of size 30000x10000 or more. This is a NatTable image. Using the standard approach to creating an image, it fails with various problems: OutOfMemory, SWTError - IllegalArgument or my computer stops responding (by the way, its Windows 7, 64bit, 4 RAM - the client has much slower laptops, but the image still needs to be created) Here is a snippet of code:

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 maybe an API? Is Java Advanced Imaging Api Right For This?

Any suggestions are welcome.

+4
source share
2 answers

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

+1
source

You can use BigBufferedImage . It has the real benefit that it saves the image on the hard drive and you don’t need to worry about the heap size or the physical memory limit . It can store a maximum of 2,147,483,647 pixels (or 46.340 x 46.340 pixels).

Create an empty BigBufferedImage:

  BigBufferedImage image = BigBufferedImage.create( tempDir, width, height, type); 

Load an existing image in BigBufferedImage:

  BigBufferedImage image = BigBufferedImage.create( imagePath, tempDir, type); 

Display part of image:

  part = image.getSubimage(x, y, width, height); 

For more information on large image processing, read this article .

+1
source

Source: https://habr.com/ru/post/1394559/


All Articles