Hello all,

I am having a problem in creating an image by using createImage() method when trying to load large files.

FileConnection fc = (FileConnection) Connector.open("file:///" + path + "/",Connector.READ);
InputStream fis = (InputStream) fc.openInputStream();
image = Image.createImage(fis); // I got the out of memory exception here.

Are there any ways to resize the image from the stream first before using createImage()?

Thanks!

Recommended Answers

All 10 Replies

I don't see the createImage method in any docs for the Image class. Post a link to the doc for me please? Also, why would it be able to construct an Image from an InputStream? What you want to do is read the data from the InputStream, then construct an Image from the data... right? So do that instead...

Also, you might want to look into the ImageProducer class. I didn't look into it much, got to get to sleep, but see if it has anything useful...

Thank for the reply, I am going to implement this on real mobile device which I could not modify the heap size. :)

Then the image is simply too big. You need to modify the image before attempting to load it into your app.

Is there any other way to do that? Anyway, I appreciate your response about this.... Thank you! :)

masijade>Then the image is simply too big. You need to modify the image before attempting to load it into your app.

squinx22>Is there any other way to do that?

Are you game with us?

Well, to "scale" the image, you would first have to have it loaded.

The only other way is to know the structure of the image file, and the original size and density parameters of the image (which can also, usually, be obtained somewhere in the file), so that you can read the file, a part at a time, restructuring/scaling as you go and write that, a part at a time, into a new file, which you could then load as an image.

This, of course, takes intimate knowledge of the storage structure of the image format in question, of course.

Thank for the reply, I am going to implement this on real mobile device which I could not modify the heap size. :)

If you are creating mobile device application then first you try them in sample devices.You are working on J2ME and which is slightly different from normal java.

Remember one thing the memory size of mobile phone is limited.The screen resolution,width and height is not same for all handsets. So everytime you need to test your application on sample device and then when its ready upload them to mobile phones.

When creating image in J2ME, you should use doublebuffer for creating them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.