【问题标题】:How to stretch to fit background image on live wallpaper如何拉伸以适合动态壁纸上的背景图像
【发布时间】:2012-05-08 16:33:02
【问题描述】:

我正在尝试设置我的动态壁纸的背景,以便完美地适合屏幕。当前壁纸尺寸为 1024x1024,但只有部分图像出现在我的 HTC Desire 屏幕上(尺寸为 480 x 800)。 此外,当我尝试设置小于 480x800 的图像时,图像不会拉伸以适应整个屏幕。

有没有什么方法可以做到这一点,使壁纸至少在高度上完美贴合,而与屏幕尺寸无关?

这是我的代码供您参考-

private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 720;


@Override
public EngineOptions onCreateEngineOptions() {
 final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
 return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}


@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
 .
 .
 this.mBitmapBackgroundAtlas1 = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024);
 this.mFaceBackgroundRegion1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapBackgroundAtlas1, this, "bg1.jpg", 0, 0);
 this.mBitmapBackgroundAtlas1.load();
 .
 .
}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
 this.mEngine.registerUpdateHandler(new FPSLogger());
 .
 .
 mScene.setBackground(new SpriteBackground(new Sprite(0, 0, mFaceBackgroundRegion1, this.getVertexBufferObjectManager())));
 .
 .
}

【问题讨论】:

    标签: android andengine live-wallpaper


    【解决方案1】:

    好的...找到答案了。发布给那些也在寻找相同的人。

    您可以覆盖 onSurfaceChanged 方法,该方法具有宽度和高度作为参数。这给出了您设备的屏幕宽度/高度。

    您可以使用此值将图像缩放到您的要求。

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
     this.screenWidth=width;
     this.screenHeight=height;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 2011-11-12
      相关资源
      最近更新 更多