0

私はcanvasでいくらかの価値を持っており、次の値を取得する必要があります。

// This one:
window.devicePixelRatio

// and any one of:
Context2d.webkitBackingStorePixelRatio ||
Context2d.mozBackingStorePixelRatio ||
Context2d.msBackingStorePixelRatio ||
Context2d.oBackingStorePixelRatio ||
Context2d.backingStorePixelRatio

これらはGWTの同等のクラスでは利用できないようです(私は思います)-それらを取得するためにネイティブメソッドを作成する必要がありますか、それともそれを行うためのより良い方法がありますか?

ありがとう

4

1 に答える 1

1

確かにコア gwt クラスでは利用できないので、jsni を使用して実装する必要があります。

別のオプションとして、gwt-2.5.0 に含まれているこれらのメソッドを持つ elemental を使用する方法がありますが、elemental は webkit にのみ実装されています。

[編集]

必要な jsni メソッドを使用して独自の context2 クラスを作成し、オーバーレイ キャストを使用して gwt context2 をクラスに変換できます。

  public class MyContext2 extends Context2d {
    public final native float webkitBackingStorePixelRatio() /*-{
      return this.webkitBackingStorePixelRatio;
    }-*/;    
  }

  Context2d ctx = ...;

  // call your method through the cast()
  float ratio = ctx.<MyContext2>cast().webkitBackingStorePixelRatio();

  // or convert the context to your class
  MyContext2 mctx = ctx.cast();
  float ratio = mctx.webkitBackingStorePixelRatio();
于 2012-11-24T17:21:44.607 に答える