Getting the right coordinates of the visible part of a UIImage inside of UIScrollView -


i have uiimage inside uiscrollview can zoom-in , zoom-out, crop, move around, etc.

how coordinates of visible part of uiimage inside uiscrollview. want crop image in it's native resolution (using gpuiimage) need x, y, width , height rectangle.

i use scrollview enable zoom of uiimage. cropping button presents overlaid resizable cropping view. following code use ensure user defined crop box in uiscrollview gets added correct coordinates uiimageview (can use crop image).

to find x , y coordinates use scrollview contentoffset multiplied inverse of zoomscale:

float origx = 0; float origy = 0; float widthcropper = 0; float heightcropper = 0;   if (_scrollview.contentoffset.x > 0){     origx = (_scrollview.contentoffset.x) * (1/_scrollview.zoomscale); } if (_scrollview.contentoffset.y > 0){     origy = (_scrollview.contentoffset.y) * (1/_scrollview.zoomscale); } 

if need create sized cropping box displayed in scrollview need adjust width , height zoom factor:

widthcropper = (_scrollview.frame.size.width * (1/_scrollview.zoomscale)); heightcropper = (_scrollview.frame.size.height * (1/_scrollview.zoomscale)); 

and add sized rectangle cropping view uiimageview:

cgrect croprect = cgrectmake((origx + (side_margin/2)), (origy + (side_margin / 2)), (widthcropper - side_margin), (heightcropper  - side_margin)); _cropview = [[uiview alloc]initwithframe:croprect]; [_cropview setbackgroundcolor:[uicolor graycolor]]; [_cropview setalpha:0.7]; [_imageview addsubview:_cropview]; [_imageview setcropview:_cropview]; 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -