将 UIImageView 中的图像保存到 iPad 照片库

Save image in UIImageView to iPad Photos Library(将 UIImageView 中的图像保存到 iPad 照片库)

本文介绍了将 UIImageView 中的图像保存到 iPad 照片库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 iPad 应用程序,它在水平滚动视图中有几张图片 (UIImageViews).我想让用户在点击 UIImageView 之一时能够将图像保存到他们的照片库中.我喜欢 Safari 处理此问题的方式:您只需点击并按住直到出现弹出菜单,然后单击保存图像.我知道有UIImageWriteToSavedPhotosAlbum".但我是 iOS 开发的新手,我不太确定该去哪里以及放在哪里(即如何检测哪个图像被点击).

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).

根据我的发现,我看到人们使用 UIImage 而不是 UIImageView.我需要将视图转换为 UIImage 吗?如果是这样,怎么做?如何检测用户何时点击图像,以及点击了哪个 UIImageView?如果你能指出我正确的方向,也许还有一些例子,我将不胜感激.

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.

推荐答案

您可以使用 UIImageViewimage 属性来获取当前图像:

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);

这篇关于将 UIImageView 中的图像保存到 iPad 照片库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将 UIImageView 中的图像保存到 iPad 照片库