Hasmukh
Hasmukh

Reputation: 4670

How i cn set Backgroungd image in Blackberry?

i want to set background image in Vertical field manager. i had try but it not fill with height you can see that in my screen. and Following in my code what i am doing mistake please help me.

 vfmCenter = new VerticalFieldManager(FIELD_HCENTER)
   {            
    public void paint(Graphics graphics)
         {

         graphics.clear();
         graphics.drawBitmap(0, 0,deviceWidth,deviceHeight,newimg,0,0);               
         super.paint(graphics);
          }      

          protected void sublayout( int maxWidth, int maxHeight)
          {
             int width = Display.getWidth();
             int height = Display.getHeight();
             super.sublayout( width, height);
             setExtent( width, height);
          }         
          };        

vfmMain.add(vfmCenter);             
        this.add(vfmMain);

enter image description here

Upvotes: 3

Views: 469

Answers (3)

Swati
Swati

Reputation: 1179

I was also facing the same issue earlier.. I solved my problem with this..

class MyClass extends MainScreen
{
    // function for scaling your image to fit the screen

    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);  
    } 
   public MyClass
   {
       ei = EncodedImage.getEncodedImageResource("res/background_image");   
       ei1= scaleImage(ei,requires_width,required_height);
       vfm= new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT|VerticalFieldManager.USE_ALL_WIDTH);
       vfm.setBackground(BackgroundFactory.createBitmapBackground(ei1.getBitmap()));
       vfm.add(new LabelField("hello notice the background behind me");
       add(vfm);
   }
}

Try this. I think it will work for you!!

Upvotes: 2

Parag Chauhan
Parag Chauhan

Reputation: 35946

This is the simple using getMainManager but whole background not a particular Field Manager

getMainManager().setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("sample.png")));

Upvotes: 0

alishaik786
alishaik786

Reputation: 3726

Try like this:

VerticalFieldManager vertical=new VerticalFieldManager()
{
    protected void paint(Graphics g) 
    {
        g.drawBitmap(0, 0,Display.getWidth(), Display.getHeight(), bitmap, 0, 0);
        super.paint(g);
    }
    protected void sublayout(int maxWidth, int maxHeight) 
    {
        super.sublayout(Display.getWidth(),Display.getHeight());
        setExtent(Display.getWidth(),Display.getHeight());
    }
};      
add(vertical);

you can get.

Upvotes: 0

Related Questions