如何使用Java在BlackBerry应用程序中设置背景图像?

时间:2011-01-24 09:07:38

标签: blackberry

我如何在java黑莓模拟器中设置背景图像?

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);
        }            

    };

3 个答案:

答案 0 :(得分:2)

试试这篇博文:
How to set Background Image in Blackberry

或者这个支持论坛帖子:
drawing bitmap in Mainscreen background

答案 1 :(得分:0)

     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);

答案 2 :(得分:0)

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);
        }        

};