在我的 j2me 应用程序中,我尝试了 Canvas ,它在诺基亚手机上运行良好,但不能在三星上运行。为此,我必须切换到某种表格,在这两种情况下都有效,但唯一的问题是大小,如果我创建较小的图像以适合两个手机屏幕,一个(三星)显示可以,但其他(诺基亚)留下更多空间反之亦然。
我需要有可以拉伸(stretch)图像的代码,并且只需将其修复为我基本上通过 form.getHeight()
和 form.getWidth()
获得的屏幕尺寸> 属性(property)。我想知道是否有 Image.createImage(width, height)
属性那么为什么它不将其拉伸(stretch)到我提供的值?
我的代码如下
try {
System.out.println("Height: " + displayForm.getHeight());
System.out.println("Width: " + displayForm.getWidth());
Image img1 = Image.createImage("/bur/splashScreen1.PNG");
img1.createImage(displayForm.getHeight(), displayForm.getWidth());
displayForm.append(new ImageItem(null, img1, Item.LAYOUT_CENTER, null));
} catch (Exception ex) {
}
图片
最佳答案
单个图像无法适合所有屏幕。但更多就可以了。
较小的 Logo 图像应小于 96x54,因为这是最小的屏幕分辨率。该图像的分辨率可达 128x128,没有任何问题。不过,分辨率越高,它看起来就越小。
较大的 Logo 图像应比 128x128 稍大,并且最大可使用 240x320。
下面的代码给出了如何实现这一点的示例。
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
class Splash extends javax.microedition.lcdui.Canvas {
Image logo;
Splash () {
if (getWidth() <= 128) {
// sl stands for Small Logo and does not need to have a file extension
// this will use less space on the jar file
logo = Image.createImage("/sl");
} else {
// bl stands for Big Logo
logo = Image.createImage("/bl");
}
}
protected void paint (Graphics g) {
// With these anchors your logo image will be drawn on the center of the screen.
g.drawImage(logo, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);
}
}
如http://smallandadaptive.blogspot.com.br/2008/10/showing-splash.html中所示
关于java-me - 修复启动画面图像以在 j2me 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13696843/