I did nothing but setting up my captured image into UIImageview
No extra custom settings
No transformation
No resizing, nothing
Then why my image view returns rotated image.
I found the solution using
UIImage* rotatedImage = [UIImage imageWithCGImage:image.CGImage
scale:1.0
orientation:UIImageOrientationRight];
Now, I get original image. But though I just want to know the reason for automatic rotated image.
Note: this happens only when picture is captured from cam, if we choose picture from gallery then it doesn't get rotated & looks proper.
Any help is appreciated !!
This could depend on the extra "shooting information" eventually added by your camera. E.g. if you take a picture with an iPhone in portrait mode ("vertical") then the image will still have the original size (2048x1536) but with the "orientation" shooting information set to "rotate 90deg". Probably UIImageView doesn't read the shooting information and show the image as "raw", that is rotated (this is the image that has been physically taken by the sensor).
Consider this: if you rotate the iPhone the physical sensor will be rotated too and the iPhone "artificially" shows the image for you to display is correctly.
You can check this by taking two photos with your iPhone, in both orientations, and then connecting the iPhone to your Mac and start the "Image Capture" app. You will see that the two photos have the same size but one will be rotated vertically. You can check the shooting information instead using Preview.
As far as the "picture taken from gallery", my guess is that the gallery does the orientation for you and returns to you not the raw image but the image after the orientation has been applied (exactly as you did in your code).
Related
I have this annoying problem where Safari Mobile rotates the pictures I take with the phone camera. The weird thing is that it only happens while in portrait mode.
Here's a code sample: http://jsfiddle.net/Kazpp/
As you can see I'm adding the image as background of the preview div and setting the background-size property as cover so I can keep the image aspect ratio and fill the whole div area with the image.
I also tried adding an image element as children of my div, but that didn't worked either.
Does anyone have any clue on what's going on here?
Ps.: I'm having this issue on iOS 6.0. Didn't tried another iOS version.
You're running into an Exif orientation issue JS Client-Side Exif Orientation: Rotate and Mirror JPEG Images
As answered in that post you can use this library to check image orientation and rotate accordingly https://github.com/blueimp/JavaScript-Load-Image
I am working on an app which is fully dependent on images. I have images like 320*480 now I want those same images with 768*1024 dimension. I can get it by UI designer and place in my bundle but my application is for universal app so I needed to include same image for iPhone retina, iPad, iPad retina. If I am using multiple images my IPA size goes increase (ex: if an image with 320*480 having 200KB now if I again adding 768*1024 the size of my IPA will increased to at least 200KB).
Idea: I am placing only 320*480 images and planning to create 768*1024 images programmatically which means only one set of images I am using in my bundle.
Work done: By looking some blogs I found that using below code we can create required image sizes.
- (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
UIImage *smallImage=[UIImage imageNamed:#"1.png"];
UIImage *bigImage=[self scale:smallImage toSize:CGSizeMake(768, 1024)];
[UIImageJPEGRepresentation(bigImage,2.0) writeToFile:[[self applicationDocumentsDirectory]stringByAppendingPathComponent:#"upload.png"] atomically:YES];
Problem: Above code works cool and getting the expected size of images but only problem is I am getting pixel distortion on the end image.
Question:
Is there any good or efficient solution to get different dimensions with out distortion image from the small image or I need to get all my images from the UI designer. If we have normal Image can we create same image for retina display?
Is there a better solution?
It is impossible to create a larger image from a smaller image without distortion or pixelation. There is no way to magically fill in the additional detail.
The real world doesn't work like TV or movies where people zoom in on images and magically get a lot of detail. :)
If you feel that your app is too big when you include 5 sets of images for:
iPhone 3.5" non-retina
iPhone 3.5" retina
iPhone 4" retina
iPad non-retina
iPad retina
then you have a few options:
Make two apps. One for iPhones and iPod touches, and one for iPads.
Ship your app with only a small subset of images. Then when the app is run the 1st time, the app can download only the images required for the current device.
Only include the largest images. As the app needs each image, it can create a properly sized version of the image and use that. Each conversion would only need to be done once per image. Downsizing an image gives much better results than trying to upscale.
You can resize image programmatically but they will not look good. I wouldn't worry that much about bundle size. Just put native-resolution image for all devices and forget about resizing.
If you want, you can crop and scale down from the big images, but if you are scaling up, there will be quality loss because the file does not contain enough information for all of those pixels. I would suggest either:
1) The easiest method is to make a bunch of different versions of the image. (see rmaddy's answer).
2) If you really don't want multiple images, take the largest one and scale downwards. Since they have different aspect ratios, simply scaling will cause some distortion; you will need to crop as well.
Either way, you will need to open up your image editor and make a larger image.
I am in the middle of creating a custom background page with simple UIImage inside a UIImageView.
What I am trying to do is to be able to fit my image the way photos app handles images.
for default portrait camera pics : seems like an aspectToFill?
for default landscape camera pics : aspectToFit for whole page (320,480)
other custom saved pics: ???
Here, I want to avoid as much empty space possible without hurting how images are perceived to the users.
Thanks for your suggestions
you must use aspectFit if you want to see the whole image, at the correct aspect ratio.
you are assuming that its aspectFill for portrait. But that'd be true only for a portrait image being viewed in Portrait (or a landscape image viewed in landscape).
I have a UIImage, from either device's camera or downloaded from a URL. Say resolution is 800x600.
I want to display a scaled image in a UIImageView which is 200x150, and I have a proper image scaling code.
So, I just scale the UIImage to the UIImageView's frame.size (again, 200x150). On a non-retina display it looks OK, but on a retina display it looks bad, like a smaller picture was scaled up, because the actual frame in pixels is 400x300.
The question is - should I, manually multiply the frame.size.width/height by 2 when it's a retina display when I resize, so it'll be resized to 400x300, or is there a built in feature for that?
Since the UIImage is not a resource on the device, I don't have the #2x option.
Keep the frame size of the image view at 200x150 in all cases.
In case of non-retina display scale the image to 200x150. On retina display devices scale it to 400x300. Set the contentMode of the UIImageView to UIViewContentModeScaleAspectFit.
When you get the image in say 800x600, can't you make a UIImage that is scaled to 400x300 and save it temporarily with the #2x extension, maybe to the Documents folder or tmp folder, and then save another UIImage scaled to 200x150 and save it without the #2x in the same directory.
My application supports taking pictures from iPhone in portrait mode and upload to the server.
However, the pictures taken are appearing in sideways once uploaded to the server.
Please help!
-KC
Keep in mind that the image has an associated imageOrientation property that will determine the correct orientation to display the image.
Images captured used AV Foundation (at least using AVCapture, which I'm using) are taken in landscape mode, so you have to rotate them clockwise before sending to the server.