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);开发者_StackOverflow社区
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.
Your path is wrong, copy the image into /res/img. To retrieve that, use the file name only.
Bitmap logoBitmap = Bitmap.getBitmapResource("icon2.png");
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);
}
精彩评论