Setting the image capture view in AVCaptureStillImageOutput class - iphone

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

Related

Clipping issues when picking from uiimagepicker

I have been dealing with this issues for a few days now trying to figure out why images are clipping whenever I pick from the uiimagepicker. I have this button in my view controller that will take on the image that is chosen from the uiimagepicker. The image shows up but there is this weird clipping affect where it shows the entire image but there is this empty space that is black that makes the image look like it is being clipped.
The image of what the issue I am dealing with is below:
image of the current clipping issues
As now, your image view content mode is .fit that's why this is happening, For now, You need to set imageView content mode scaleAspectFill:
imageView.contentMode = UIViewContentMode.scaleAspectFill
imageView.clipsToBounds = true

iOS background and images seem to not scale properly for retina display

When using the following code:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"texture1.png"]];
The texture background of my view gets set just fine. But I can see that the images are not scaled properly for a retina display, they seem more pixelated, rather than rich in texture and color as they should be. I have had this issue with other images too, when trying to make an image the size of the iphone 5 screen fade away, only a part of it would be seen, and the rest would be cut off, even though the resolution is fine. Any idea what I am missing here?
EDIT: Does it have to do with the default dpi of the images that I am using?
EDIT #2: Here is a screenshot:
On a side note, does anyone know if good background texture sources besides http://subtlepatterns.com/?
EDIT #3: Here is a good example of me attempting to use the ios-linen pattern
firstly remove .png from image name if you are use #2x image
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"texture1"]];
Please check the image height and width for retain display ..
By Apple On devices with high-resolution screens, the imageNamed:, imageWithContentsOfFile:, and initWithContentsOfFile: methods automatically looks for a version of the requested image with the #2x modifier in its name. If it finds one, it loads that image instead. If you do not provide a high-resolution version of a given image, the image object still loads a standard-resolution image (if one exists) and scales it during drawing.
Instead of using initWithPatternImage you should add a UIImageView to the UIView . This is better because :-
The UIImageView will contain the image according to its specific width and height.
Also, the initWithPatternImage method consumes MORE MEMORY than the UIImageView.
I would prefer to use a UIImageView rather than the
initWithPatternImage:[UIImage imageNamed:#"texture1.png"]
If the image is still not clear you can add the #2x image to the UIImageView and you will see the clarity is more.

CPGraphHostingView background image issue in IPhone?

I have a CPGraphHostingView to display a graph. I changed its theme to clear color, and add a UIImageView to the CPGraphHostingView in order to add an image as the background of the graph.
But then the image will give only the mirror image like copy of the original image. So when I am taking the screenshot of that view I'm getting the mirror image copy of the original view. How to solve this?
Don't add any subviews to the CPGraphHostingView. If you must use a UIImageView, make it a sibling of the hosting view (i.e., they are both subviews of the same parent).
The easiest way to put an image behind a graph is to set the fill.
CPTImage backgroundImage = [CPTImage imageForPNGFile:pathToTheImage];
graph.fill = [CPTFill fillWithImage:backgroundImage];
You can also create the image using +imageWithCGImage: or +imageWithCGImage:scale: if you already have your background image loaded into a CGImageRef.

Crop uiimage as screen size

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;

How can I change the inner image position of an UIImageView?

I have defined an UIImageView in my nib. After the app launches, I display an image in that UIImageView. Maybe I am on the wrong way, but what I want to do is the following:
The image which I load into the view is bigger than the view itself. I want that it is displayed in original size with hidden overlay. Then I want to slowly move that image inside that view in random directions.
Maybe you know html div containers with background images. there, you can set a position of that background image and change that position with JavaScript. I need something similar on iPhone.
Maybe an UIImageView is not the right thing for that? Or must I set the UIImageView to the full size of that image and then move the UIImageView around slowly? Could it be bigger than the iPhone's screen?
You need to crop the image. See Lounges' answer to this question.
This is the gist of my answer to pretty much the same question:
There isn't a simple class method to do this, but there is a function that you can use to get the desired results: CGImageCreateWithImageInRect(CGImageRef, CGRect) will help you out.
Here's a short example using it:
CGImageRef imageRef = CGImageCreateWithImageInRect([largeImage CGImage], cropRect);
[UIImageView setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);