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
New Contributor
Posts: 4
Registered: ‎06-01-2012
My Device: Torch 9800
My Carrier: Idea
Accepted Solution

Scaling images without severing aspect ratio

Im in a situation where i need to scale images in terms to the container in which its kept..

Is there any formula to find the scale value that should be applied to the image( I have set the max size of the container)??? Any ideas put forward would be very kind..

Thanks.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Scaling images without severing aspect ratio

Welcome to the forum.

 

I am not sure I understand the issue here.

 

Say you have an image of height a and width b.  You want to scale it to fit in a container of width x and height y.  Then the scaling factor that you should use, to make sure the image fills the container as much as possible, without upsetting the aspect ratio is simply

 

min(x/a, y/b)

 

An example,  assume your image is 100 x 150 and you want to fit it in an area that 30 x 40

the formula gives:

 

min(30/100, 40/150)

 

This, when scaled will fill the entire height, but not the width. 

 

Hope this makes sense. 

Highlighted
New Contributor
Posts: 4
Registered: ‎06-01-2012
My Device: Torch 9800
My Carrier: Idea

Re: Scaling images without severing aspect ratio

Greatly appreciate your help.

 

I could scale the image on both height and width by using

max(image.getHeight()/container.getHeight(), image.getWidth()/container.getWidth())

 

Once again thanks a lot.