2

私のj2meアプリでは、ノキアの電話ではうまく機能するが、サムスンでは動作しないキャンバスを試しました。そのためには、どちらの場合も機能するいくつかのフォームに切り替える必要がありますが、問題はサイズだけです。両方の電話画面に合わせて小さい画像を作成すると、1 つ (samsung) は問題なく表示されますが、もう 1 つ (nokia) はより多くのスペースを残しますおよびその逆。

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

画像ここに画像の説明を入力

4

2 に答える 2

3

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に見られるように

于 2012-12-04T20:05:37.623 に答える
0

のプロパティがあるのだろうかImage.createImage(width, height)、なぜそれを私が提供する値に引き延ばさないのですか?

このメソッドのパラメータは Stretching とは関係ありません。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

Imageclass ( API javadocs )にはcreateImage、「width」と「height」というパラメーターを使用するメソッドがさらに2あります。

  • 6createImageつの引数を使用して、幅と高さはソース イメージからコピーされる領域のサイズを指定します (ストレッチなし)。

  • 4 つの引数を持つメソッドでは、幅と高さはソース ARGB 配列の解釈方法を指定します。これらがないと、12値の配列が画像を表しているの3x44x3. 繰り返しますが、これはStretchingとは関係ありません。

于 2012-12-05T08:45:22.717 に答える