Results 1 to 11 of 11
- 12-29-2011, 05:49 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
Merge jpeg files using one BufferedImage
Hi. I've got huge image which I would like to encode as jpeg. Unfortunately I can't read it as one piece into memory (OOM exception) so I'd like to read it piece by piece and iteratively write it to file. Is it possible to make it with ImageIO? I found writeInsert method which is responsible for that, but it doesn't work for me. UnsupportedOperationException is thrown on each attempt of using it. Does anybody know how can I deal with that?
Thanks for any suggestions
- 12-29-2011, 06:52 PM #2
Re: Merge jpeg files using one BufferedImage
Just curious. How large is the image file? What program created it?
To be able to read parts of it an make sense of those parts you would need to know the internal format of the file.
Is the file a concatenation of a number of other image files? If so, if you could detect the boundaries between the images, you could read the sub parts and make images of them.
- 12-29-2011, 07:11 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
Re: Merge jpeg files using one BufferedImage
well the image is generated by ILog component embedded in our web UI. It's IBM product for vector graphics etc... The image can be of resolution even like 100k x 100k pixels (it's our limit, in theory it can be bigger I guess) which gives 28GB of data in RGB.
Generated picture can be zoomed, scaled, transformed, rotated, moved and much more so cutting it and reading chunks of it is quite simple through api. The problem appeared when one of our clients started to have big topology and wanted to export it into image of big resolution. (OOM due to allocating BufferedImage for whole picture)...
so the problem here is not getting chunks of image but saving them in one file one by one.
Feel free to ask more questions if you need to know anything more
- 12-29-2011, 07:17 PM #4
Re: Merge jpeg files using one BufferedImage
Still not sure what you expect.
If the file contains ONE image , do you want to read any part of it and create a smaller image file from the part that was read?
What format is the large image file in?
- 12-29-2011, 09:17 PM #5
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
Re: Merge jpeg files using one BufferedImage
not exactly... The thing I want to achieve is to encode in jpeg the image that comes from ILOG (IBM's component mentioned above). ILOG has print method which fills BufferedImage object. Step by step it looks like this:
ILOG stores whole image in vector form so it's very compressed and extremely scalable.
User might want to have a big picture of his topology (ILOG can scale, zoom, move, etc...)
problem is here when picture is about to be written in BufferedImage as RGB if user wants to have 100kx100k resolution out of memory is thrown...
so I want to get part of picture scale and save as jpeg... then get second part scale and append to the jpeg file... get n'th part... well you get the idea.
and I've got everything prepared already, but I am unable to append content to jpeg because writeInsert isn't supported
still unclear? I don't know maybe I shall post some snippets of code?
- 12-29-2011, 09:31 PM #6
Re: Merge jpeg files using one BufferedImage
when picture is about to be written in BufferedImage as RGB if user wants to have 100kx100k resolution
Are you going to divide that into 4 50kX50K image files for example?
append to the jpeg file
- 12-30-2011, 12:22 AM #7
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
Re: Merge jpeg files using one BufferedImage
well making 4 or n image files out of one topology is unacceptable. I need to have one file showing whole view... and it seems that it is impossible to append content to already existing jpeg image. That's why I asked. Anyway thanks a lot maybe there will be someone who will know what can I do about it
- 12-30-2011, 12:30 AM #8
Re: Merge jpeg files using one BufferedImage
Let me restate what you're trying to do.
You have a source(file) of data the can be used to create an image but the size of the image is too large to fit into memory. You want a program that will read data little by little from the source, configure it and write it out into the superlarge image and do it in some way that the whole of the image is never in memory at one time.
You might be able to do that to create a bmp file.
What can be done with this superlarge image file once it is created?
- 12-30-2011, 11:47 AM #9
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
Re: Merge jpeg files using one BufferedImage
source(file)
size of the image is too large to fit into memory
You want a program
I tried to use ImageIO in order to do that, but it seems that jpeg plugin doesn't allow to do that (or I don't know how and that's why I am asking ;))
You might be able to do that to create a bmp file
What can be done with this superlarge image file once it is created?
Ok. I guess some code will be needed. Here's how the picture is acquired:
Java Code:BufferedImage targetImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics graphic = targetImage.createGraphics(); graphic.setColor(Color.WHITE); graphic.fillRect(0, 0, targetImage.getWidth(), targetImage.getHeight()); graphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphic.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); sourceManager.print(graphic, sourceArea, sourceView, transformer, false);
sourceView is the whole topology(it is not hold as a picture so it can be in memory as a whole view)
transformer are geometry transformations like scaling, moving, rotating, etc that will be put on sourceArea before it's written in graphic
After calling print, graphic can be disposed and a picture of topology will be drawn in targetImage (it needs to be alocated with proper size, so if I try to allocate to much memory for pixels OOM is thrown)
And back to the source of the problem - If user wants to have a big resolution picture of his topology I can't select whole topology and do print on it. I need to select it piece by piece and write it to a file as jpegLast edited by carek; 12-30-2011 at 11:55 AM.
- 12-30-2011, 02:15 PM #10
Re: Merge jpeg files using one BufferedImage
user that requested the view of his topology can then without turning on and logging in to our product see topology
Can you talk about your project in terms of bits and bytes and programs?
You keep using your application's terminology that has no meaning for me.
Some where there is a source of bytes (a web component???). You want to read those bytes with a java program, reformat them and write them out as a jpg file. The problem you are having is that there are too many bytes to fit into your PC's memory. What you need is a java program that will read some bytes, convert them and write them out a few at a time so that the whole never needs to be in memory at one time.Last edited by Norm; 12-30-2011 at 02:22 PM.
- 12-30-2011, 02:31 PM #11
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
Re: Merge jpeg files using one BufferedImage
You keep using your application's terminology that has no meaning for me.
That is what I don't understand. How is the user able to look at the image? What software/program does he have that is able to load the supersized image for viewing?
...and yes, I guess your description fits the problem more or less
Similar Threads
-
Merge Two Xml files ????
By alwz_nikhil in forum XMLReplies: 5Last Post: 01-18-2011, 10:18 AM -
Merge 2 pdf files with itext and preview on servlet
By xampos20 in forum New To JavaReplies: 1Last Post: 05-12-2010, 12:49 AM -
Help with moving jpeg files
By Umi in forum New To JavaReplies: 11Last Post: 09-30-2009, 02:11 AM -
How to Merge two Files
By svpriyan in forum New To JavaReplies: 2Last Post: 04-28-2009, 12:34 PM -
How do merge two xml files into one xml?
By veera in forum XMLReplies: 1Last Post: 03-27-2008, 06:06 PM
Bookmarks