Welcome!

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

Reply
Contributor
Josimol
Posts: 28
Registered: ‎07-06-2011
My Device: 9800

Adjusting the image size for different simulators

I am a fresher to the blackberry development

I have created a project for blackberry 8520

But the images are not fitted for other simulators with different screen size

How I can adjust the image size for the different simulators

can anybody help me with sample code?

Now iam using iamge with fixed size

Regular Contributor
nag
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800

Re: Adjusting the image size for different simulators

Hi, josimol.....

u can scale the image to big size or small size but.....

u cant change the image dimensions automatically for the different simulators................

 

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Contributor
Josimol
Posts: 28
Registered: ‎07-06-2011
My Device: 9800

Re: Adjusting the image size for different simulators

How I can scale that one

Images are given for button editfields etc...

is it possible to scale all those images also?

can you give me a sample code?

Regular Contributor
nag
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800

Re: Adjusting the image size for different simulators

yaa ofcourse it is possible to scale the image

package mypackage;

import net.rim.device.api.system.Bitmap;

public class Scale {
	
	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;
   }


   public static Bitmap resizeBitmap(Bitmap image, int width, int height)
   {       
           //Need an array (for RGB, with the size of original image)
            //
            int rgb[] = new int[image.getWidth()*image.getHeight()];

             //Get the RGB array of image into "rgb"
               //
            image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());

          //Call to our function and obtain RGB2
        //
            int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);

          //Create an image with that RGB array
         //
            Bitmap temp2 = new Bitmap(width, height);

            temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
           
              return temp2;
   }

    public Bitmap bestFit(Bitmap image, int maxWidth, int maxHeight)
       {

            // getting image properties
             int w = image.getWidth();
             int h = image.getHeight();

           //  get the ratio
              int ratiow = 100 * maxWidth / w;
              int ratioh = 100 * maxHeight / h;

                            // this is to find the best ratio to
                          // resize the image without deformations
              int ratio = Math.min(ratiow, ratioh);

        // computing final desired dimensions
           int desiredWidth = w * ratio / 100;
           int desiredHeight = h * ratio / 100;
          // imgscale = ratio;

         //resizing
            return resizeBitmap(image, desiredWidth, desiredHeight);
      }
}

 just use this class and change the size as follows

BitmapField bitmap1 =

new BitmapField(Scale.resizeBitmap(myBitmap1,60, 60),BitmapField.FOCUSABLE)

 

here 60,60 are the height and width co-ordinates of the image ...u can change as u like

 

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Contributor
Josimol
Posts: 28
Registered: ‎07-06-2011
My Device: 9800

Re: Adjusting the image size for different simulators

Thank you....

its working now...........

Regular Contributor
nag
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800

Re: Adjusting the image size for different simulators

k ........go ahead.......it will work for only bitmap images.....if u want to resize encoded image u need to follow other procedure...
Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Contributor
Josimol
Posts: 28
Registered: ‎07-06-2011
My Device: 9800

Re: Adjusting the image size for different simulators

For the Button Images will it work?

Regular Contributor
nag
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800

Re: Adjusting the image size for different simulators

what exactly meant by "ButtonImages"...?

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Contributor
Josimol
Posts: 28
Registered: ‎07-06-2011
My Device: 9800

Re: Adjusting the image size for different simulators

Actually i given some images with button properties

its working as button now

But i have those buttons should fix in ll the simulators.

Is there any solution for that one?

 

Contributor
Josimol
Posts: 28
Registered: ‎07-06-2011
My Device: 9800

Re: Adjusting the image size for different simulators

I have one more doubt

When we are giving  BitmapField bitmap1 = new BitmapField(Scale.resizeBitmap(_bitmap,60, 60),BitmapField.FOCUSABLE);, how we can access the height and width of the simulator?

otherwise i have to hardcoded its height and width.

that is not possible for all simulators.......