I’m drawing a Bitmap as a background for a custom field but it doesn’t draw the bitmap in the entire field’s area. I’ve resized the image too but it always leaves out some space to the right and bottom. This is what it looks like:

Here’s some code for painting:
public int getPreferredWidth(){
return phoneWidth;
}
public int getPreferredHeight(){
return cellHeight;
}
protected void paint(Graphics g) {
Bitmap img = Bitmap.getBitmapResource("cell_bg.png");
img.scaleInto(new Bitmap(phoneWidth, cellHeight), Bitmap.SCALE_TO_FIT);//or other scaling methods
g.drawBitmap(0, 0, phoneWidth, cellHeight, img, 0, 0);//draw background
//other steps
}
It works fine if I set the Background as follows-
Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("cell_bg.png"),0,0,Background.REPEAT_SCALE_TO_FIT);
this.setBackground(bg);
but this way, the background image is not visible onFocus.
What am I doing wrong here?
The problem here is you’ve used
scaleInto()incorrectly.Try it like this:
the
scaledbitmap image is given as output, NOT the original image .