Reputation: 19
i hav written a code which is following...
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class Immutable extends MIDlet implements CommandListener {
private Display display;
private Form form;
private Command exit;
private Image image;
private ImageItem imageItem;
public Immutable() throws IOException
{
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
form = new Form("Immutable Image Example");
form.addCommand(exit);
form.setCommandListener(this);
try
{
image = Image.createImage("/hello/minion.png");
imageItem = new ImageItem("This is the IMAGE_ITEM Application",
image,ImageItem.LAYOUT_NEWLINE_BEFORE |ImageItem.LAYOUT_LEFT |
ImageItem.LAYOUT_NEWLINE_AFTER, "My Image");
form.append(imageItem);
}
catch (java.io.IOException error)
{
Alert alert = new Alert("Error", "Cannot load minion.png.",null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable Displayable)
{
if (command == exit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
now this image named minion.png is of 32kb and pixel size 803x825. in this case the image is not getting loaded perfectly. i have tried it on emulator and also on nokia 3110. it is giving error saying "out of memory".
same thing is running nicely with another image of size 6kb and pixels 96x96.
please suggest some idea to store an big image. thnx in advance...
Upvotes: 0
Views: 626
Reputation: 3909
more efficient way to resize an image: http://www.developer.nokia.com/Community/Wiki/Scale_/_Resize_images_in_Java_ME
Upvotes: 0
Reputation: 240860
First you aren't storing any image by this code, just displaying.
Now all mobile device have limitation of memory. You can't load this big image if you device is running out of memory in any case.
You need to make it smaller and load the smaller version of image.
Upvotes: 1