Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hi VSN first of all cut the selected part from your imageview</p> <p>using this code</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tactile_noise.png"]]; self.imageCropper = [[BJImageCropper alloc] initWithImage:[UIImage imageNamed:@"gavandme.jpg"] andMaxSize:CGSizeMake(1024, 600)]; [self.view addSubview:self.imageCropper]; self.imageCropper.center = self.view.center; self.imageCropper.imageView.layer.shadowColor = [[UIColor blackColor] CGColor]; self.imageCropper.imageView.layer.shadowRadius = 3.0f; self.imageCropper.imageView.layer.shadowOpacity = 0.8f; self.imageCropper.imageView.layer.shadowOffset = CGSizeMake(1, 1); [self.imageCropper addObserver:self forKeyPath:@"crop" options:NSKeyValueObservingOptionNew context:nil]; if (SHOW_PREVIEW) { self.preview = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,self.imageCropper.crop.size.width * 0.1, self.imageCropper.crop.size.height * 0.1)]; self.preview.image = [self.imageCropper getCroppedImage]; self.preview.clipsToBounds = YES; self.preview.layer.borderColor = [[UIColor whiteColor] CGColor]; self.preview.layer.borderWidth = 2.0; [self.view addSubview:self.preview]; } } </code></pre> <p>check this example</p> <p><a href="https://github.com/barrettj/BJImageCropper/downloads" rel="nofollow">https://github.com/barrettj/BJImageCropper/downloads</a></p> <p>OR <strong>To crop the selected image part do like that</strong></p> <pre><code>// Create the image from a png file UIImage *image = [UIImage imageNamed:@"prgBinary.jpg"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; // Get size of current image CGSize size = [image size]; // Frame location in view to show original image [imageView setFrame:CGRectMake(0, 0, size.width, size.height)]; [[self view] addSubview:imageView]; [imageView release]; // Create rectangle that represents a cropped image // from the middle of the existing image CGRect rect = CGRectMake(size.width / 4, size.height / 4 , (size.width / 2), (size.height / 2)); // Create bitmap image from original image data, // using rectangle to specify desired crop area CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect); UIImage *img = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); // Create and show the new image from bitmap data imageView = [[UIImageView alloc] initWithImage:img]; [imageView setFrame:CGRectMake(0, 200, (size.width / 2), (size.height / 2))]; [[self view] addSubview:imageView]; [imageView release]; </code></pre> <p>Refer this</p> <p><a href="http://mobiledevelopertips.com/graphics/how-to-crop-an-image.html" rel="nofollow">http://mobiledevelopertips.com/graphics/how-to-crop-an-image.html</a></p> <p>OR To Resize the uiiamgeview do like that</p> <pre><code>- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize { CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height)); CGImageRef imageRef = image.CGImage; UIGraphicsBeginImageContextWithOptions(newSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); // Set the quality level to use when rescaling CGContextSetInterpolationQuality(context, kCGInterpolationHigh); CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height); CGContextConcatCTM(context, flipVertical); // Draw into the context; this scales the image CGContextDrawImage(context, newRect, imageRef); // Get the resized image from the context and a UIImage CGImageRef newImageRef = CGBitmapContextCreateImage(context); UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; CGImageRelease(newImageRef); UIGraphicsEndImageContext(); return newImage; } </code></pre> <p><strong>After crop or resize the your image to apply <code>UIPanGestureRecognizer</code></strong></p> <pre><code>UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)]; [panRecognizer setMinimumNumberOfTouches:1]; [panRecognizer setMaximumNumberOfTouches:1]; [panRecognizer setDelegate:self]; [holderView addGestureRecognizer:panRecognizer]; -(void)move:(id)sender { [[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations]; [self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]]; CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view]; if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) { firstX = [[sender view] center].x; firstY = [[sender view] center].y; } translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y); [[sender view] setCenter:translatedPoint]; if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { CGFloat finalX = translatedPoint.x + (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].x); CGFloat finalY = translatedPoint.y + (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y); if(UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) { if(finalX &lt; 0) { finalX = 0; } else if(finalX &gt; 768) { finalX = 768; } if(finalY &lt; 0) { finalY = 0; } else if(finalY &gt; 1024) { finalY = 1024; } } else { if(finalX &lt; 0) { finalX = 0; } else if(finalX &gt; 1024) { finalX = 768; } if(finalY &lt; 0) { finalY = 0; } else if(finalY &gt; 768) { finalY = 1024; } } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.35]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; [[sender view] setCenter:CGPointMake(finalX, finalY)]; [UIView commitAnimations]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload