iOS: saving UIImageView to Camera Roll - ios

Even though this sounds super simple, I got stuck on this because of how my app works.
I have a UIImageView that loads an online image. On the app, I will have a button that gives the user a choice to export the image to Camera Roll.
Most solutions such as UIImageWriteToSavedPhotosAlbum don't work with UIImageView.
Should I first capture a UIImage from the UIImageView and then save to Camera Roll? How? Or can I save directly?

The UIImage is a representation of an image. UIImageView is a container for displaying that image in your app. What you need to save is the image, not the container.

Related

Want fixed orientation, but the UIImage autoratate

I am confused about the UIImage orientation in my iOS design.
I simply load an image taken by my iPhone into UIImageView using storyboard and expect it would be shown exactly the same in the simulator. However, it rotates.
(I choose the content mode to be aspect fit)
I try with other images downloaded from the internet all of them works fine but the one was taken by the camera.
Anyone have any idea why this happens?
edit:
I try to print out imageOrientation property my example. It shows 0 which is the default value of .up.
It seems the picture has not been rotated but it looks different in storyboard and simulator.
The example would be as following:
The UIImage is rotated automatically , the developer should rectify it.
use the below function to get the image in the correct orientation.
UIImage *imageToDisplay = [UIImage imageWithCGImage:[originalImage CGImage] scale:[originalImage scale] orientation: UIImageOrientationUp];
A UIImage has a property imageOrientation, which instructs the UIImageView and other UIImage consumers to rotate the raw image data. There's a good chance that this flag is being saved to the default data in the uploaded jpeg image, but the program you use to view it is not honoring that flag. Try changing the orientation while fetching image from UIImage Picker Controller.
To rotate the UIImage to display properly when uploaded, you can use a category. Check #Anomie's ans in Objective C. If you are using Swift you can create your extension for UIImage using same logic.

Choosing Photo's from Camera Roll on every device

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

Adding rotation to UIImage in the ImageView- not the ImageView in iOS app

I am trying to add a user interactive rotation option to iOS app. I don't want to rotate the imageView but want to rotate the UIImage displayed on the imageView. I know how to do it on the imageView.
It is important to add the procedure through which image is provided to the imageView. I first take the image from Camera or Photo Library. Then, I crop the image using a crop tool created. I have followed the following code for the crop:
https://github.com/johnomarkid/BFCropInterface
After the crop I want to rotate the image like Photos Edit option in iPhone. Can anyone help in this regard?

iOS Native Image Cropping with image OUTSIDE of UIImagePickerController

So, if I select an image with the UIImagePicker from the camera or camera roll, before I return to my app, it provides this great cropping feature.
I was hoping that there was a way to call this crop API directly without going through the camera or camera roll. If I have an existing image in an app (for instance a user profile photo) and the user wants to re-crop that image, can I open the crop tool?
I haven't seen anything about calling this crop tool outside of UIImagePicker.

UIImage from UIImagePickerController orientation issue

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

Resources