Crop uiimage as screen size - iphone

My application have an function that allow user to move and scale the image just like setting allowsEditing = YES with UIImagePickerController.
My approach is having a scrollview which allow user to zoom with level 1-4
There is only a image view on the scrollview.
At the end, I want to crop the image as the screen size. How can I do it?

The trick is to capture the layer of the view containing the scaled / rotated image. In this case you need to capture the scrollview layer NOT the image itself.
I have a UIImage capture category for this...check out my article and download the source code.
UPDATE: to crop part of the image as per the comment below...
First capture the whole view then crop the image to the specified rect using the following method in the UIImage+Resize category (also in the article...)
- (UIImage *)croppedImage:(CGRect)bounds;

Related

Pinch and Pan to Crop UIImage

I want to add a Pinch and Pan gesture that will crop the UIImage views on my ViewController. To crop the images, just pinch/pan the appropriate image and it will resize.
I currently have the Take Pic and Choose Image buttons grab the appropriate images into the UIImageView boxes accordingly, but I want to be able to pinch and pan to size and crop the image in the view.
I want the box to stay fixed at its current size, and the image within will be the one resizing and cropping.
PS. I am using storyboard
Here is a screenshot of what I have.
http://i.stack.imgur.com/chkk5.png
I was thinking that the right direction would be to add a swipe and pan gesture to each uiimageviews in storyboard, but not sure what to do after.
My general strategy for this in the past has to been place the UIImageView inside another UIView (in order to clip it) and add a UIPinchGestureRecognizer and a UIPanGestureRecognizer to the parent UIView. When you receive events for either of these you apply the appropriate transformation to the transform property of the UIImageView.
When scaling, for example, you would do the following:
-(void)scale:(UIPinchGestureRecognizer*)pinch
{
float scale = pinch.scale;
imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
pinch.scale = 1;
}
The final step of reseting the scale is important because you are simply scaling the existing transform each time rather than a base identity transform. You should find that you will be able to handle translating the transform by using a UIPanGestureRecognizer and its translationInView: method (remember you will also have to reset this with setTranslationInView:CGPointZero.
Finally, in order to get a cropped/clipped UIImage out you can either capture the view's contents (I believe the transform property is only respected on iOS 7+) or alternatively render the UIImage into a CGContextRef, and using the same transform to transform the CGContextRef.
You can use below link...
Crop image

Setting the image capture view in AVCaptureStillImageOutput class

I am using AVCaptureConnection and AVCaptureStillImageOutput class to create a overlay screen and capturing the image.In the view,I have a custom tab bar with some custom controls like capture button,flash button etc.
The problem is that the camera is capturing the whole image and it is seen in the preview page.i.e. the custom tabbar is of 40 pixels,so the user is shown the capture area with the tab bar.User takes the image till the custom tabbar.but in the preview screen,the image gets extended and he sees extra apart from the image he took.
I tried looking up for property in AVCaptureConnection to set the capture area but couldn't found anything.Anyone has faced the issue earlier,please help.
As you can see the user is seeing the extra apart from what he has taken
I don't think there is a way to set the capture area in AVCaptureConnection. Instead you could try to read the image off the screen and then crop it to your requirement.
If UIImage *photoImage is the image being returned on capturing the photo
CGRect refRect; //Define this to the exact frame which you want to crop the larger image to i.e. with smaller frame.size.height
CGFloat deviceScale = photoImage.scale;
CGImageRef imageRef = CGImageCreateWithImageInRect(photoImage.CGImage. refRect);
UIIImage *finalPhoto = [[UIImage alloc] initWithCGImage:imageRef deviceScale orientation:photoImage.imageOrientation];
The finalPhoto will now be cropped to what you want

resize an imageview with two fingers iPhone

In my application users can load/take a photo, put it into a frame and move, rotate and scale it as they want.I know how use a uiScrollView as a normal view and load inside of it an image, but in this case the image is large as the view, and i want it is large as i want. How can i do this?
for moving and scaling an image.you can just use the following default picker function in UIImagepicker.
picker.editing =YES;

UIImageView, UIView, taking a segment of a picture

I want to take an image from the UIImagePickerController and put it on a UIImageView that can move based on touch. I'm not sure how to get the picture onto the UIImageView. I thought the UIImageView automatically resizes the picture, so I couldn't grab just the top half of the picture and put that on the UIImageView. Is there an easy way to do this? thanks!
Use CGImageCreateWithImageInRect to crop (take a segment of?) a picture. Put a UIImageView inside a UIScrollView to let the user scroll through (move based on touch) a large image.
if you want to move and zoom your picture in a view, you need to use a UIScrollView. See Apple's ScrollViewSuite example. If you simply want to position the picture within a UIImageView, set the contentMode of the UIImageView to the setting you want e.g. scale, top, left, etc. See the UIImageView documentation for all options.

How to set the image into fit screen in the image view

I am new to iphone development. I want to display the actual size of the image in image view. I have created image view by using Interface builder and set the properties. Now the problem is, I have set into "Scale to Fill", then the image will be stretched in the full screen. Now i want to display the actual size of the image will be displayed in image view. For example 52X52 size image should be displayed with the same size in the image view.The 1200X1020 size image should be fit to the size of the image view .So according the size of the image it should fit to image view and i want the image smaller than image view should retain its original size(It should not stretch to fit the image view).
Is it any possible solution to achieve it, please guide me.
Thanks.
You're going to have to check the dimensions on the UIImage yourself and then set the proper property on the UIImageView: myImage.contentMode = UIViewContentModeCenter , etc
The different content modes: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewContentModeScaleToFill