How to make UI in blackberry including images in such a way that it works in different screen resolutions devices?

心已入冬 提交于 2019-12-11 14:43:03

问题


I am developing an application which will run on different blackberry devices.

640 x 480
800 x 480
360 X 480
320 X 240
480 X 360

Please tell me how can i handle these resolutions. I have used Differnt PicturebackgroundField, EditFields, etc.


回答1:


There is no single way to handle different resolution in Blackberry. You can use following way:

CASE 1. Resizing and scaling the images for different resolution.

CASE 2. Create single build by including images for each target resolution.

CASE 3. Create a single source code and build different cod file for different resolution by replacing the images.

pros and cons:

CASE 1: this way provide the poor quality. PNG image scaling do not provide the good result.

CASE 2: this way will be good for small project which uses less images.

CASE 3: by using this way, you can implements the layout code according to screen height and width and then build the application by replacing the images for different resolution. I think this is the reason Blackberry provides the facility to upload different COD for different resolution.




回答2:


Taking the Device width & height and according to that you can manipulate:

 int width=Display.getWidth();
 int height=Display.getHeight();

From these width and height you can CROP and SCALE the images.




回答3:


There are 2 approaches to this, both with pros and cons:

1. Resize your images on app startup

Include only the largest resolution images with your app resources, then scale them down based on the device screen resolution. This approach has two problems: 1. It can take time to perform the image resizing which can affect your startup time 2. The BlackBerry resizing function is not that great and may create images which are pixelated. If you want to do it this way here's some code:

public class DisplayConfig {

    public static EncodedImage scaleImageToHeight(EncodedImage encoded, float newHeight) {
        return scaleToFactor(encoded, encoded.getHeight(), (int)newHeight);
    }

    public static EncodedImage scaleToFactor(EncodedImage encoded, int curSize, int newSize) {
        int numerator = Fixed32.toFP(curSize);
        int denominator = Fixed32.toFP(newSize);
        int scale = Fixed32.div(numerator, denominator);

        return encoded.scaleImage32(scale, scale);
    }
}

Usage example:

EncodedImage titleLogoEnc = EncodedImage.getEncodedImageResource("title-background-logo.png");

if (currentDisplayFormat == SCREEN_FORMAT_320_BY_240){

    float scaleFactor = 2F/3; //0.6 recurring
    titleLogoEnc = DisplayConfig.scaleImageToHeight(titleLogoEnc, titleLogoEnc.getHeight() * scaleFactor);  
}

2. Include images for each target resolution

If your images are small to start with the file size overhead for doing this is minimal, and the image quality is far better. The practical limit for download on App World is around 5MB so it's up to you to judge whether having images for each supported resolution will make your resulting application too large.




回答4:


You can resize or scale your images according to your screen requirements by using

BitMap_Instance.scaleInto(0, 0, image.getWidth(), image.getHeight(), ret, 0, 0, 
desiredWidth, desiredHeight, Bitmap.FILTER_BILINEAR);


来源:https://stackoverflow.com/questions/8165145/how-to-make-ui-in-blackberry-including-images-in-such-a-way-that-it-works-in-dif

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!