How do you set the background image in a BlackBerry application using Java?

。_饼干妹妹 提交于 2019-12-12 01:35:44

问题


how i set background image in java blackberry simulator ?

backgroundBitmap = Bitmap.getBitmapResource("background.png");
MainScreen mainScreen = new MainScreen();

HorizontalFieldManager horizontalFieldManager = 
    new HorizontalFieldManager(
        HorizontalFieldManager.USE_ALL_WIDTH | 
        HorizontalFieldManager.USE_ALL_HEIGHT){

        //Override the paint method to draw the background image.
        public void paint(Graphics graphics) {
            //Draw the background image and then call paint.
            graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0);
            super.paint(graphics);
        }            

    };

回答1:


try this blog post:
How to set Background Image in Blackberry

Or this support forum thread:
drawing bitmap in Mainscreen background




回答2:


     Bitmap bitmapOrig = Bitmap.getBitmapResource("ICON.png");            
      // Create a Bitmap of arbitrary size
      int scaledX = 360;
      int scaledY = 415;
      Bitmap bitmapScaled = new Bitmap(scaledX, scaledY);
      bitmapOrig.scaleInto(bitmapScaled , Bitmap.FILTER_LANCZOS);                       
      bitmapOrig.scaleInto(bitmapScaled , Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);                       
      BitmapField bitmapFieldScaled2 = new BitmapField(bitmapScaled , Field.FOCUSABLE);
     homeScreen.add(bitmapFieldScaled2);



回答3:


HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(
                                HorizontalFieldManager.USE_ALL_WIDTH | 
                                HorizontalFieldManager.USE_ALL_HEIGHT){

    //Override the paint method to draw the background image.
    public void paint(Graphics graphics) {
        //Draw the background image and then call paint.
        graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0);
        super.paint(graphics);
    }    
   protected void sublayout(int maxWidth, int maxHeight){ 
            super.sublayout(240,240);
            setExtent(240,240);
        }        

};


来源:https://stackoverflow.com/questions/4780230/how-do-you-set-the-background-image-in-a-blackberry-application-using-java

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