iphone - crop a zoomed image in ImageView inside scrollView -
I already try very much from my side. Finally I need help Thanks
Target: 1) How do I crop a zoomed image inside the scrollView?
2) How do I crop the image inside the image.
I have an image view inside the scroll. I want a crop image after zoom in, which is displayed inside the scrollview range. I have already created an image, but this is not exactly what I have to do.
Here I set the background scroller in my scrollView. And when I show the image inside it, then it is not fit.
Then zoom the image inside the scroll view
and after the crop image
And my code is here:
- (zero) viewDidoadload {[Super Viewedload]; CGRect frame 1 = CGRactam (50,50,200,200); CGRect frame2 = CGRactack (50,50,200,200); ImageView1 = [[UIImageView alloc] initWithFrame: frame1]; ImageView1.image = [UIImage imageNamed: @ "back.jpeg"]; ImageView1.backgroundColor = [UIColor Brown Collar]; ImageView1.contentMode = UIViewContentModeScaleAspectFit; Scroll = [[UIScrollView alloc] initWithFrame: frame2]; Scroll.backgroundColor = [UIColor blackColor]; [Scrollsviewview: imageView1]; Scroll.delegate = self; [Self.view addSubview: scroll]; [Self-set contentisforforcroll view]; Self.imageView1.userInteractionEnabled = Yes; } Set the screen view content
- (zero) setContentSizeForScrollView {// scroll.contentSize = CGSizeMake (imageView1.frame.size.width, ImageView1. frame.size.height); Scroll.contentSize = CGSizeMake (200, 200); Scroll.minimumZoomScale = .50; Scroll.maximumZoomScale = 1.5; } and my crop logic
- (IBAction) Calculate the required area from cropButtonClicked {// ScrollAv = CRGRact = CGRactMake (50, 50, 200,200); UIImage * image = [Self ImageBeekCropping: imageView1.image toRect: rect]; ImageView1.image = Image; ImageView1.contentMode = UIViewContentModeScaleAspectFit; } and crop image of this method:
- (UIImage *) imageByCropping: (UIImage *) reset myImage: (CGRect) cropToArea { CGImageRef cropImageRef = CGImageCreateWithImageInRect (myImage.CGImage, cropToArea); UIImage * cropped = [UIImage imageWithCGImage: cropImageRef]; CGImageRelease (cropImageRef); Refunded; }
Answer to my own question: Afterwards I got the answer to both of my questions. And this works well for me I share here, maybe it helps someone :)
1) See the image fit inside the picture. I use it
- (zero) centerScrollViewContents {CGSize boundsSize = scroll.bounds.size; Cgarte contentframe = self.majvie 1.frame; If (Content Fro. Size.width & lt; boundsize.width) {contentsFrame.origin.x = (Borders Size.width - contentsFrame.size.width) / 2.0f; } And {contentFrame.origin.x = 0.0f; } If (content is fighter size.height & lt; boundsize.height) {contentFrame.origin.y = (limitations height = contentframe.height) / 2.0f; } And {contentFrame.origin.y = 0.0f; } Self.imageView1.frame = contentFrame; } 2) Crop a zoomed image inside the scrollview. I use it
UIGraphicsBeginImageContext (CGSizeMake (200, 200)); [Scroll.layer renderIncontext: UIGraphicsGetCurrentContext ()]; UIImage * fullScreenshot = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); ImageView1.contentMode = UIViewContentModeScaleAspectFill; UIImageWriteToSavedPhotosAlbum (full screenshot, zero, zero, zero); Full return screenshots;
Comments
Post a Comment