我编写了以下代码...
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();
}
}
}
现在这个名为 minion.png 的图像大小为 32kb,像素大小为 803x825。在这种情况下,图像无法完美加载。我已经在模拟器和诺基亚 3110 上尝试过。它给出错误“内存不足”。
同样的事情在另一个大小为 6kb、像素为 96x96 的图像上运行得很好。
请提出一些存储大图像的想法。提前谢谢...
最佳答案
首先,您不会通过此代码存储任何图像,只是显示。
现在所有移动设备都有内存限制。如果您的设备在任何情况下内存不足,您都无法加载这个大图像。
您需要将其缩小并加载较小版本的图像。
关于java - 如何通过J2ME存储大图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5242721/