Ted pottel
Ted pottel

Reputation: 6993

Trying to draw a bitmap on blackberry

I'm just learing how to program the blackberry and trying to display a bitmap on the screen, here is the code:

public MyScreen()
{        
    // Set the displayed title of the screen       
    setTitle("MyTitle2");
    LabelField lb = new LabelField("hello ted2");
    add(lb);

    Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png");
    BitmapField fd= new BitmapField(logoBitmap, Field.FIELD_HCENTER);
    add(fd); 
}

The label is drawn but not the bitmap.

Upvotes: 2

Views: 651

Answers (2)

Your path is wrong, copy the image into /res/img. To retrieve that, use the file name only.

Bitmap logoBitmap = Bitmap.getBitmapResource("icon2.png");

Upvotes: 2

MusiGenesis
MusiGenesis

Reputation: 75396

I think you need to put the two fields into a VerticalFieldManager:

public MyScreen()
{        
    VerticalFieldManager vfm = new VerticalFieldManager();

    // Set the displayed title of the screen       
    setTitle("MyTitle2");
    LabelField lb = new LabelField("hello ted2");
    vfm.add(lb);

    Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png");
    BitmapField fd= new BitmapField(logoBitmap);
    vfm.add(fd); 

    add(vfm);
}

Upvotes: 1

Related Questions