hi, I am developing image redraw app. i know the center of one image view which is having scaling property. i.e it can change it frame and center . that to be applied to another view center. when i apply center to newly formed Image view it giving wrong center because of the previous image view is having scaling property. so how can i get exact center to my new image view from previous imageview
Your view or image is
width*height
your center view should always be in position
(width/2,height/2)
whether the image is scaled or not. Just recalculate your center after the scale if you need the "scaled" center or keep in memory the original center position if you don't.
Pseudocode:
getCenter(w,h){
pos[0]=w/2;
pos[1]=h/2;
return pos;
}
calc(image){
c = getCenter(image.w,image.h);
scaled = image.scale(80); //That is 80% of original
d = getCenter(scaled.w,scaled.h);
if(something) return c;
else return d;
}
Second explanation after discussion (read comments):
Let's assume you have a 640X480 image and you create a view of 320X240 (a quarter of it) and you move THIS view 100px right and 50 pixels down from position (0,0) which is usually top left corner of your image then:
your new center of the VIEW will be as usual in position (160,120) of the VIEW
the original center of the ORIGINAL image will remain in its position (320,240) which casually corresponds to the bottom right corner of your VIEW.
IF you want to know WHERE the original center of the ORIGINAL image DID end up AFTER movement and "cropping" then you just have to know where did you move the VIEW:
100px right becomes (original position - relative movement) (320 - 100) = 220 50px down becomes (original position - relative movement) (240 - 50) = 190
So your ORIGINAL center will be in position (220,190) of the new VIEW.