绘制位图作为背景MainScreen。如何拉伸图像? [英] Drawing Bitmap as MainScreen Background. How to Stretch Image?
本文介绍了绘制位图作为背景MainScreen。如何拉伸图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望背景图像伸展所有的屏幕。我只是创造了一个VerticalFieldManager和修改paint方法。
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);
}
};
当我一个ListField添加到verticalFieldManager并滚动,背景图像不会重新绘制。我怎样才能重新绘制背景时滚动?
And when i add a ListField to the verticalFieldManager and scroll, background image is not repaint. How can i repaint background when scroll?
推荐答案
创建恩codeDIMAGE
从位图
,甚至可以直接提取恩codeDIMAGE
从资源 - 恩codedImage.getEn codedImageResource(RES / BG巴纽)
。
Create EncodedImage
from your Bitmap
, or even directly extract EncodedImage
from resources - 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);
}
}
然后你可以得出恩codeDIMAGE
的图形
对象:
graphics.drawImage(
0, 0,
encodedImage.getScaledWidth(), ncodedImage.getScaledHeight(),
encodedImage, 0, 0, 0
);
这篇关于绘制位图作为背景MainScreen。如何拉伸图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文