简体   繁体   English

如何通过J2ME存储大图像

[英]how to store a big image through J2ME

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. 现在,此名为minion.png的图片大小为32kb,像素大小为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". 我在模拟器和诺基亚3110上都尝试过。它给出错误消息,提示“内存不足”。

same thing is running nicely with another image of size 6kb and pixels 96x96. 另一张大小为6kb,像素为96x96的图片也可以很好地运行。

please suggest some idea to store an big image. 请提出一些想法来保存大形象。 thnx in advance... 提前thnx ...

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. 您需要使其更小并加载较小版本的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM