Java me 修复要在j2me中显示的启动屏幕图像

Java me 修复要在j2me中显示的启动屏幕图像,java-me,nokia,midp,lcdui,jsr75,Java Me,Nokia,Midp,Lcdui,Jsr75,在我的j2me应用程序中,我尝试了canvas,它在诺基亚手机上运行得很好,但在三星手机上不运行。为此,我必须切换到某种形式,在这两种情况下都有效,但唯一的问题是尺寸,如果我创建更小的图像以适应两个手机屏幕,其中一个(三星)显示ok,但另一个(诺基亚)留下更多的空间,反之亦然 我需要有可以拉伸图像的代码,只需将if固定到屏幕大小,我基本上是通过form.getHeight()和form.getWidth()属性获得的。我想知道是否有Image.createImage(宽度、高度)的属性,那么为什

在我的j2me应用程序中,我尝试了canvas,它在诺基亚手机上运行得很好,但在三星手机上不运行。为此,我必须切换到某种形式,在这两种情况下都有效,但唯一的问题是尺寸,如果我创建更小的图像以适应两个手机屏幕,其中一个(三星)显示ok,但另一个(诺基亚)留下更多的空间,反之亦然

我需要有可以拉伸图像的代码,只需将if固定到屏幕大小,我基本上是通过
form.getHeight()
form.getWidth()
属性获得的。我想知道是否有
Image.createImage(宽度、高度)
的属性,那么为什么它不将其拉伸到我提供的值呢

我的代码如下

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) {
    }

图像

单个图像不能适合所有屏幕。但更多的就行了。
较小的徽标图像应小于96x54,因为这是最小的屏幕分辨率。此图像的分辨率可达128x128,没有问题。不过,如果分辨率更高,它看起来会很小。
较大的徽标图像应该比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);
  }
}
导入javax.microedition.lcdui.Image;
导入javax.microedition.lcdui.Graphics;
类Splash扩展了javax.microedition.lcdui.Canvas{
形象标识;
飞溅(){
if(getWidth()
不知道是否存在
Image.createImage(宽度、高度)
的属性,那么为什么它不将其拉伸到我提供的值

此方法中的参数与拉伸无关,请参见:


Image
class()还有两个
createImage
方法,它们使用名为“width”和“height”的参数,一个带有,另一个带有参数,但这些都与拉伸无关

  • 在具有六个参数的
    createImage
    中,宽度和高度指定要从源图像复制(不拉伸)的区域大小

  • 在有四个参数的方法中,宽度和高度指定了如何解释源ARGB数组,如果没有这些参数,就不可能确定
    12
    值的数组是否表示
    3x4
    图像或
    4x3
    。同样,这与拉伸无关


这是一个更接近的、可能的解决方案,我还想知道一件事,Image.createImage(高度、宽度)是什么;与未创建图像时的图像高度和宽度有关/将其拉伸到我们给定的值?如果您再次阅读我的问题,我对画布有问题,因此这不适用于我用于此应用程序的所有手机!createImage(int,int)=“为屏幕外绘图创建一个新的可变图像。新创建图像中的每个像素都是白色的。图像的宽度和高度都必须大于零。”它不执行拉伸。重要的是if/else块。根据屏幕宽度选择一个imagem。我添加了显示图像的图像。createImage(宽度,高度)在我的问题中,我所说的方法。而关于拉伸图像,我的意思是,它不是创建了一个宽度和高度相同的图像,或者不管图像的大小,它只是给它一个值的空间吗?如果你再次看到,你提供的链接中包含了该方法!@Saqib很好,谢谢-我更正了回答。不幸的是,即使纠正,也没有拉伸。。。
 public static Image createImage(int width, int height)

    Creates a new, mutable image for off-screen drawing.
        Every pixel within the newly created image is white.
        The width and height of the image must both be greater than zero.

    Parameters:
        width - the width of the new image, in pixels
        height - the height of the new image, in pixels