Save image in UIImageView to iPad Photos Library

Brian picture Brian · Nov 16, 2010 · Viewed 18.6k times · Source

I am creating an iPad app that has several pictures (UIImageViews) in a horizontal scrollview. I want to allow the user to be able to save the images to their Photo Library when they tap on one of the UIImageViews. I like the way Safari handles this matter: you just tap and hold until a pop up menu appears and then click save image. I know there is the "UIImageWriteToSavedPhotosAlbum". But I am a newbie to iOS development and I'm not too sure where to go with it and where to put it (i.e. how to detect which image was tapped).

From what I have found, I have seen people use UIImage instead of UIImageView. Do I need to convert my view to UIImage? If so, how? How do I detect when the user taps the images, and which UIImageView was tapped? If you could point me in the right direction, and maybe some examples I would greatly appreciate it.

Answer

bosmacs picture bosmacs · Nov 16, 2010

You can use the image property of a UIImageView to get the current image:

UIImage* imageToSave = [imageView image]; // alternatively, imageView.image

// Save it to the camera roll / saved photo album
UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil);