I'm using UIImagePickerController to fetch images from the user's photo library and/or taken with the camera. Works great.
I'm noticing that fetched images are often (always?) coming back with their imageOrientation set to UIImageOrientationRight. But the image was captured with the device in portrait orientation. Why is this? This is an iPhone4S, iOS6, using the rear camera - so the resolution is 8MP.
In the simulator, grabbing photos from the photo library, images come back UIImageOrientationUp.
When I display the image in a UIImageView the orientation looks correct (portrait/up). But when I go to crop the image the coordinate system isn't what I would expect. 0,0 is in the upper-right of the image, which I guess makes sense when it reports UIImageOrientationRight.
I'm looking for an explanation of what's going on and the correct approach to dealing with the odd coordinate system.
EDIT: it sure appears to me that, on iPhone4S at least, the camera always takes UIImageOrientationRight/"landscape" images, and that UIImageView is respecting the imageOrientation on display. However, if I save the image using UIImagePNGRepresentation the orientation is not preserved (I think I read about this somewhere.)
It has to do with the orientation the phone was in when the image was taken. The phone doesn't rotate the image data from the camera sensor to make up in the image be up but instead sets the imageOrientation and then UIImage will take care of rendering things the right way.
When you try and crop, you typically change the image to be a CGImage and that loses the orientation information so suddenly you get the image with a strange orientation.
There are several categories on UIImage that you can get that will perform image cropping while taking imageOrientation into account.
Have a look at link or link
Related
I'm coding an app where users can upload pictures and add some filters to it.
The problem is that when I apply filter on it, the picture is rotating, ONLY if the picture has been taken with back camera.
If it was a selfie the picture is not rotating
If the picture is in portrait mode, the picture is not rotating
The problem is that I don't know how I could get these information, in order to rotate the picture only when I need it.
You're thinking about this the wrong way. It may be the case that images taken with your phone's rear camera appear rotated after applying a filter, but you cannot make this assumption for all devices. Instead, you can read the imageOrientation property on UIImage to obtain information about whether the image has an unusual rotation.
I have an app that chooses an image from the Camera Roll or Takes a photo using the Camera. The problem is that when I run the app on an iPad, if I select an image it doesn't display the full image later on.
Image you select : (Notice that the waterfall is pretty much entered.)
Image displayed : (The image is displayed wrong)
The problem is only on big devices like iPads. I'm saving the image using CoreData and then recovering it. How can I get it to display the full I'm age?
Niall
You need to set UIImageView contentMode to ScaleAspectFit
I'm using UIImagePickerController to snap an image and uploading it to server.
When taking a photo in the front camera, the height/width get reversed somewhere.
The image is displayed correctly later, but height and width are reversed (and I'm using them for the UIImageView autolayout constraint)
The thing is - that when looking at UIImagePickerControllerMediaMetadata of front and back camera images - the EXIF and the rest of the metadata is the same (resolution is smaller but the height/width ratio is the same)
Any ideas what is the difference?
Apple images are always landscape left with EXIF and the orientation is specified in the EXIF.
OK, so #zaph comment is correct, apparently back camera images are "reversed" as well - the upload code in the server (Codeigniter PHP) ignored the EXIF.
The problem surfaced only due to front camera low resolution...
I'm using GLKTextureLoader to load images from the photo roll, but any time an image that was shot in portrait aspect ratio is loaded, it ends up being treated as a landscape aspect image, rotated 90 degrees off.
I believe the UIImage from the photo roll will need to be rotated and redrawn using Quartz, but I don't really know where to begin. I thought I might be able to modify the popular UIImage+Resize.h library, but when I try to load a UIImage that has been simply resized with that library, the GLKTextureLoader fails, suggesting to me that some information it relies on is lost in the process.
In my app I use a custom camera and when I snap a photo I want to see it in an UIImageView, it's all ok it work, but there is a little problem: when it put the UIImage (from camera) in UIImageView, the image sems a little flattened, then what's the exactly resolution that I should to set for UIImageView to have an exactly copy of my original UIImage?
ok, I set aspect fill in IB and it's all ok
The images resolution depends on the device that you are using. For the iPhone 4, it's 2592x1936.
I think it's more likely that you might be looking for the aspect ratio for the image, which is always 4:3. Keep in mind however, that a) you don't know whether the image will be portrait or landscape and b) that, if you allow to take an image from a photo album, you don't have control over the resolution/ratio at all.
So the most prudent thing to do might be to just set the UIImages fill mode to 'Aspect Fill' or 'Aspect Fit'.