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
aviraljain
Posts: 18
Registered: ‎05-02-2011
My Device: Torch 9800
My Carrier: Airtel
Accepted Solution

Setting center of image scaling

Hi,

I'm trying to implement pinch zooming functionality in Blackberry Torch. I can get pinch details from touchevent and accordingly calculate scaling factors. I can then scale the image using EncodedImage.scaleImage32.

However, I also need to set the center of scaling, as during pinch zooming, I need to keep the point between two fingers fixed, instead of 0,0. I can't find a method to set the center of scaling.

Any ideas?

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Setting center of image scaling

I would look at this another way, rather than scaling about a centre, I think you have to scale and then re-center.  In other words, scale it, then figure out where the new centre point would be based on the centre of the fingers after the scale.  The paint the Bitmap centered at that location. 

 

I suspect this is easier than trying to figure out how to scale and maintain the centre point. 

Please use plain text.
Contributor
aviraljain
Posts: 18
Registered: ‎05-02-2011
My Device: Torch 9800
My Carrier: Airtel

Re: Setting center of image scaling

Hmm... seems that will work too.
I'm putting the image in a Manager with both vertical and horizontal scroll enabled, so that the user can pan through the zoomed-in image. So how can I set the center point on the manager after scaling the image?
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Setting center of image scaling

It is just math....

 

Say your pinch point is curently at x = 1000 and y = 1100, and you are scrolling so the left hand edge you are displaying is 900 and the top of the screen you are displaying is 800.  So your centre point is 100 in from the right hand side and 300 down.

 

Say you reduce the image by 20%, so the pinch point is now 800, 880.  You need to position this 100 in and 300 down, so the horizontal scroll position will be 800 - 100, and the vertical scroll position will be 1100 - 300. 

 

Or something like that.

 

I'm sure if you try to picture this and draw diagrams you will figure the math out.

 

Good luck. 

Please use plain text.
Contributor
aviraljain
Posts: 18
Registered: ‎05-02-2011
My Device: Torch 9800
My Carrier: Airtel

Re: Setting center of image scaling

Ok I've got it working.
Thanks.
:smileyhappy:
Please use plain text.