java - 如何通过J2ME存储大图像

标签 java java-me out-of-memory

我编写了以下代码...

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/

相关文章:

java.lang.nullpointerException 在 android.content.contextwrapper.getsystemservice(Contextwrapper.java :386)

java - Weblogic JMS 客户端 - 在单个事务中从多个队列读取

java - j2me 应用程序不能在手机上运行

android - React native Android 的 OutOfMemoryError 的原因

java permgen 对于 Linux 上的 swing 应用程序内存不足,但在 Windows 上则不然

javascript - Azure MobileService EasyApi java.lang.interruptedException

Java GUI MasterMind

java-me - 如何识别j2me中的特定声音频率?

java - J2ME 应用程序显示???编译后的字符

android - Android 中 String、StringBuffer 和 StringBuilder 的内存不足异常