[英]Creating a javax.microedition.lcdui.Image on J2Se Application
我已經為J2Me設計了一個組件,這是paint方法:
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
class Component {
...
public void paint(Graphics g) {
if (background != null)
g.drawImage(image, bounds.getLocation().x, bounds.getLocation().y, 0);
}
...
}
我想在J2Se應用程序上繪制此組件,我嘗試將組件繪制到J2Me圖像上,然后將int []提取到InputStream中,並使用此對象在J2Se平台上創建一個新圖像:
public class ComponentStreamer {
private Component component;
private Image j2Me_Image;
public void setComponent(Component component) {
this.component = component;
}
public InputStream getInputStream() throws IOException {
if(component==null)
return null;
//THIS LINE THROWS THE EXCEPTION
j2Me_Image=Image.createImage(component.getSize().width, component.getSize().height);
component.paint(j2Me_Image.getGraphics());
return getImageInputStream(j2Me_Image);
}
}
我已經嘗試了對象,但是注釋行引發了異常:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: javax.microedition.lcdui.ImmutableImage.decodeImage([BII)V
at javax.microedition.lcdui.ImmutableImage.decodeImage(Native Method)
at javax.microedition.lcdui.ImmutableImage.getImageFromStream(Image.java:999)
at javax.microedition.lcdui.ImmutableImage.<init>(Image.java:955)
at javax.microedition.lcdui.Image.createImage(Image.java:554)
如何克服這個錯誤?
謝謝,
亞當。
好,
深入研究J2Me MIDP和CLDC的源代碼以及使用名為Microemulator的軟件包的過程是一個漫長的過程,下面的代碼可以使其他人入門:
這將啟動一個模擬器,然后啟用一些J2Me功能。
private void setUpEmulator() {
try {
// overrideJ2MeImagePackageLock();
Headless app = new Headless();
DeviceEntry defaultDevice = new DeviceEntry("Default device", null, DeviceImpl.DEFAULT_LOCATION, true, false);
Field field = app.getClass().getDeclaredField("emulator");
field.setAccessible(true);
Common emulator = (Common) field.get(app);
emulator.initParams(new ArrayList<String>(), defaultDevice, J2SEDevice.class);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Un-handled Exception");
}
}
接下來,我們還有其他一些不錯的對象可以使用:
public class J2MeImageLayer extends ScalableLayer {
private static final long serialVersionUID = -4606125807092612043L;
public J2MeImageLayer() {
componentViewer.super();
}
@Override
public void repaint() {
J2SEMutableImage mutableImage = new J2SEMutableImage(page.getSize().width, page.getSize().height);
page.paint(mutableImage.getGraphics());
Graphics g = getImage().getGraphics();
g.drawImage(mutableImage.getImage(), 0, 0, DCP_Simulator.this);
}
public void addComponent(Component component) {
page.add(component);
}
public void setComponent(final Component component) {
page.removeAllElements();
final Container componentParent;
if ((componentParent = component.getParent()) != null)
component.setRemovedAction(new interfaces.Action() {
@Override
public void action() {
componentParent.add(component);
}
});
page.add(component);
}
}
這是如何做到這一點的重點。
亞當。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.