Loading large images in JavaME
Hi Everybody, Long time fan, first time caller. :D I didn't find anything in my search and hope that I have posted my question to the right place.
I am hoping someone could help me determine how to display large image files without popping the memory when loading them. At risk of stating the obvious:rolleyes:, when I say popping the memory I mean getting a java.lang.OutOfMemoryError exception.
So far when attempting to display images taken with an internal camera I have tried to use the MediaProcessor and ImageTransformControl however this method throws the aforementioned exception on the mediaProcessor.setInput() call with a large InputStream:
Another approach was to read the image in chunks, in attempts to resize the chunks then cat back together once all the pieces are loaded:
FileConnection fc = (FileConnection)Connector.open(fileName);
InputStream src = fc.openInputStream();
MediaProcessor mp = null;
mp = GlobalManager.createMediaProcessor(image/jpeg);
mp.setInput(src, MediaProcessor.UNKNOWN); //POP!
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageTransformControl fc = (ImageTransformControl)mp.getControl( javax.microedition.amms.control.imageeffect.ImageTransformControl);
return Image.createImage(bos.toByteArray(), 0, bos.size());
however an IllegalArgumentException is thrown due to the CreateImage method being unable to deccode the image chunk.:mad:
byte data = new byte[chunkSize];
int length = fis.read(data, 0, chunkSize);
Image img = Image.createImage(data, 0, chunkSize);
Open to suggestions,