123
123

Reputation:

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

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

    };

Upvotes: 0

Views: 7317

Answers (3)

iKushal
iKushal

Reputation: 2909

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

};

Upvotes: 0

123
123

Reputation:

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

Upvotes: 0

Swati
Swati

Reputation: 2918

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

Or this support forum thread:
drawing bitmap in Mainscreen background

Upvotes: 2

Related Questions