如何根据黑莓屏幕的显示宽度和高度使用代码重新调整资源文件夹中存储的图像大小?
答案 0 :(得分:1)
首先创建一个像这样的编码图像
EncodedImage ei = EncodedImage.getEncodedImageResource("res/helpscreen.png");
然后将此编码图像传递给下面的函数
EncodedImage ei1= scaleImage(ei,reqWidth,requiredHeight);
public EncodedImage scaleImage(EncodedImage source, int requiredWidth, int requiredHeight)
{
int currentWidthFixed32 = Fixed32.toFP(source.getWidth());
int requiredWidthFixed32 = Fixed32.toFP(requiredWidth);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int currentHeightFixed32 = Fixed32.toFP(source.getHeight());
int requiredHeightFixed32 = Fixed32.toFP(requiredHeight);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
return source.scaleImage32(scaleXFixed32, scaleYFixed32);
}
这将为您提供编码图像。然后使用
将其转换为Bitmap BitmapField logoBitmap = new BitmapField(ei1.getBitmap());
答案 1 :(得分:0)
要缩放Bitmap
图片,请尝试Bitmap.scaleInto(...)
。 API Link.
Bitmap targetBm = new Bitmap(Display.getWidth(), Display.getHeight());
srcBitmap.scaleInto(targetBm, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_STRETCH);