绘制位图作为主屏幕背景。如何拉伸图像?

发布于 2024-11-02 19:12:11 字数 587 浏览 3 评论 0原文

我希望背景图像能够拉伸整个屏幕。我只是创建了一个 VerticalFieldManager 并修改了绘制方法。

   verticalFieldManager = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH
                            | VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR) {
             public void paint(Graphics graphics) {
                    graphics.drawBitmap(0, 0, this.getWidth(), this.getHeight(),
                                        backgroundBitmap, 0, 0);
                    super.paint(graphics);
        }

    };

当我将 ListField 添加到 VerticalFieldManager 并滚动时,背景图像不会重新绘制。滚动时如何重新绘制背景?

I want the background image to stretch all screen. I simply created a VerticalFieldManager and modified paint method.

   verticalFieldManager = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH
                            | VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR) {
             public void paint(Graphics graphics) {
                    graphics.drawBitmap(0, 0, this.getWidth(), this.getHeight(),
                                        backgroundBitmap, 0, 0);
                    super.paint(graphics);
        }

    };

And when i add a ListField to the verticalFieldManager and scroll, background image is not repaint. How can i repaint background when scroll?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鱼窥荷 2024-11-09 19:12:11

从您的位图创建EncodedImage,甚至直接从资源中提取EncodedImage - EncodedImage.getEncodedImageResource("res/bg.png")

然后使用它来缩放它:

public static EncodedImage resize(EncodedImage eImage, int toWidth, 
        int toHeight, boolean keepAspectRatio) {

    int scaleX = Fixed32.div(
        Fixed32.toFP(eImage.getWidth()),
        Fixed32.toFP(toWidth)
    );

    int scaleY = Fixed32.div(
        Fixed32.toFP(eImage.getHeight()), 
        Fixed32.toFP(toHeight)
    );

    if (keepAspectRatio) {
        int scale = (scaleX > scaleY) ? scaleX : scaleY;
        return eImage.scaleImage32(scale, scale);
    } else {
        return eImage.scaleImage32(scaleX, scaleY);
    }
}

然后您可以在 Graphics 对象上绘制 EncodedImage

graphics.drawImage(
    0, 0, 
    encodedImage.getScaledWidth(), ncodedImage.getScaledHeight(), 
    encodedImage, 0, 0, 0
);

Create EncodedImage from your Bitmap, or even directly extract EncodedImage from resources - EncodedImage.getEncodedImageResource("res/bg.png").

Then use this to scale it:

public static EncodedImage resize(EncodedImage eImage, int toWidth, 
        int toHeight, boolean keepAspectRatio) {

    int scaleX = Fixed32.div(
        Fixed32.toFP(eImage.getWidth()),
        Fixed32.toFP(toWidth)
    );

    int scaleY = Fixed32.div(
        Fixed32.toFP(eImage.getHeight()), 
        Fixed32.toFP(toHeight)
    );

    if (keepAspectRatio) {
        int scale = (scaleX > scaleY) ? scaleX : scaleY;
        return eImage.scaleImage32(scale, scale);
    } else {
        return eImage.scaleImage32(scaleX, scaleY);
    }
}

Then you may draw the EncodedImage on the Graphics object:

graphics.drawImage(
    0, 0, 
    encodedImage.getScaledWidth(), ncodedImage.getScaledHeight(), 
    encodedImage, 0, 0, 0
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文