-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);
}
這會給你一個編碼圖像。然後將其轉換使用
BitmapField logoBitmap = new BitmapField(ei1.getBitmap());
要縮放Bitmap
圖像嘗試Bitmap.scaleInto(...)
爲位圖。 API Link.
Bitmap targetBm = new Bitmap(Display.getWidth(), Display.getHeight());
srcBitmap.scaleInto(targetBm, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_STRETCH);
張貼在這裏之前嘗試搜索類似的帖子 – Swati 2011-12-29 04:29:55