【问题标题】:fix a splash screen image to display in j2me修复在 j2me 中显示的初始屏幕图像
【发布时间】:2012-12-04 05:45:36
【问题描述】:

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

我需要有可以拉伸我的图像的代码,并且只需修复我基本上通过form.getHeight()form.getWidth() 属性获得的屏幕尺寸。我想知道是否有Image.createImage(width, height) 的属性,那么为什么不将其扩展到我提供的值?

我的代码如下

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

图片

【问题讨论】:

    标签: java-me nokia midp lcdui jsr75


    【解决方案1】:

    单个图像无法适应所有屏幕。但更多会做。
    较小的徽标图像应小于 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);
      }
    }
    

    http://smallandadaptive.blogspot.com.br/2008/10/showing-splash.html所见

    【讨论】:

    • 嗯,这是一个更接近和可能的解决方案,我想知道另外一件事,Image.createImage(height, width);当它不创建图像/将其拉伸到我们给出的值时,它与图像的高度和宽度有关吗?
    • 如果您再次阅读我的问题,我对 Canvas 有疑问,因此这不适用于我用于此应用程序的所有手机!
    • createImage(int, int) = "创建一个新的、可变的图像用于离屏绘图。新创建的图像中的每个像素都是白色的。图像的宽度和高度都必须大于零。” docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/…它不执行拉伸。
    • 重要的是 if/else 块。根据屏幕宽度选择图像。
    【解决方案2】:

    想知道Image.createImage(width, height) 是否有属性,那么为什么不将其扩展到我提供的值?

    此方法中的参数与拉伸无关,见API javadocs

     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
    

    Image 类 (API javadocs) 还有两个 createImage 方法,它们使用名为“width”和“height”的参数 - 一个使用 six,另一个使用 @ 987654324@ 个参数,但这些都与拉伸无关。

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

    • 1234563 @。同样,这与拉伸无关。

    【讨论】:

    • 我在我的问题中添加了显示 Image.createImage(width, height) 方法的图像。而关于拉伸图像,我的意思是它不会创建具有该宽度和高度的图像,或者它只是为其提供该值的空间而不管图像的大小?如果您再次看到,您提供的链接包含该方法!
    • @Saqib 很好,谢谢 - 我更正了答案。不幸的是,即使有修正,也没有拉伸...
    猜你喜欢
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    相关资源
    最近更新 更多