Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified
Accepted Solution

How to use graphics.drawBitmap

I have Bitmap of 10*15.


If i want to draw a Bitmap occuping full displaywidth and image height ,can i do it using this image.


i tried using this,But i cannot get the single image to occupy the required width.Method is


    graphics.drawBitmap(10,20,340,image.getHeight(),image 0, 0);



Is it possible?



Rakesh shankar.P

Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-, Z10 (STL100-3)-, Z30 (STA100-5)-, Passport (SQW100-1)-, PlayBook (16GB)-
My Carrier: Verizon

Re: How to use graphics.drawBitmap

drawBitmap doesn't do any scaling internally. You need to scale the Bitmap before calling the function in order to get it to take up the full width of the screen.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Posts: 263
Registered: ‎05-18-2011
My Device: Curve 9300, BB10 Dev Alpha C, Z10

Re: How to use graphics.drawBitmap

is right. You need to scale your bitmap to the required width first. You may like to use the following method to scale your bitmap by width:


Bitmap resizeByWidth(Bitmap originalBitmap, int w) {
 double ratio = (double) originalBitmap.getWidth() / (double) w;
 int h = round((double) originalBitmap.getHeight() / ratio);

 Bitmap scaledBitmap = new Bitmap(w, h);
 originalBitmap.scaleInto(scaledBitmap, Bitmap.FILTER_BILINEAR);
 return scaledBitmap;

int round(double d) {
 return (int) Math.ceil(d);