[英]how to store a big image through J2ME
我寫了下面的代碼...
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的圖片也可以很好地運行。
請提出一些想法來保存大形象。 提前thnx ...
首先,您不會通過此代碼存儲任何圖像,而只是顯示它們。
現在,所有移動設備都有內存限制。 無論如何,如果設備內存不足,則無法加載此大映像。
您需要使其更小並加載較小版本的圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.