1

I have written the following code here the background image is displaying but the image did not cover the full background

private Bitmap background;
    int mWidth = Display.getWidth();
    int mHeight = Display.getHeight();

    public MyScreen()
    {        
        // Set the displayed title of the screen  
        //backgroundBitmap = Bitmap.getBitmapResource("slidimage.png");
        final Bitmap background = Bitmap.getBitmapResource("slidimage.png");

        HorizontalFieldManager vfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) {
               public void paint(Graphics g) {
                    g.drawBitmap(0, 0,mWidth, mHeight, background, 0, 0);
                    super.paint(g);
               }
        };

        add(vfm);
Nate
  • 31,017
  • 13
  • 83
  • 207
Janmejoy
  • 2,721
  • 1
  • 20
  • 38
  • 2
    You need to scale (stretch) the Bitmap before drawing. Check this answer, http://stackoverflow.com/a/2268027/431639. `public static Bitmap resizeImage()` will solve your problem. Also read the API documentation, http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/system/Bitmap.html#scaleInto%28net.rim.device.api.system.Bitmap,%20int%29. – Rupak Dec 21 '12 at 08:40

1 Answers1

0
public static Bitmap resizeBitmap(Bitmap image, int width, int height)
    {   
        int rgb[] = new int[image.getWidth()*image.getHeight()];
        image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());        
        int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
        Bitmap temp2 = new Bitmap(width, height);        
        temp2.setARGB(rgb2, 0, width, 0, 0, width, height);        
        return temp2;
    }

You can use the above method to resize the image just pass the image to be resized and its width and height . and the function will return the resized image .

where rescale Array is the below method

private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
    {
        int out[] = new int[x2*y2];
        for (int yy = 0; yy < y2; yy++)
        {
            int dy = yy * y / y2;
            for (int xx = 0; xx < x2; xx++)
            {
                int dx = xx * x / x2;
                out[(x2 * yy) + xx] = ini[(x * dy) + dx];
            }
        }
        return out;
    }
Yatin
  • 2,969
  • 9
  • 34
  • 68