xcode 将 UIImageView 转换为 UIImage

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11500759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:54:46  来源:igfitidea点击:

Converting UIImageView to UIImage

objective-cxcodeuiimageviewuikituiimage

提问by Anatoliy Gatt

I'm working with images, I have tonnes of them, and I'm downloading them in real time from the server, before it was really fast with the AsyncImageViewclass, but know I'm working with the custom class, that takes UIImageinstead of UIImageView.

我正在处理图像,我有成吨的图像,并且我正在从服务器实时下载它们,之前AsyncImageView类的速度非常快,但我知道我正在使用自定义类,这需要UIImage而不是UIImageView.

Question:Is there any good way to convert UIImageViewto UIImage?

问题:有什么好的方法可以转换UIImageViewUIImage

Thanks in advance!

提前致谢!

回答by wattson12

you dont need to show a UIImageView inside a UIImage. Maybe you want to show a UIImageView inside another UIImageView or maybe you want to access the UIImageView's image property, which you can do with imageView.image:

您不需要在 UIImage 中显示 UIImageView。也许你想在另一个 UIImageView 中显示一个 UIImageView 或者你想访问 UIImageView 的图像属性,你可以用 imageView.image 来做:

UIImage *imageFromImageView = myImageView.image

or if its the image view inside another image view option:

或者如果它是另一个图像视图选项中的图像视图:

[myOuterImageView addSubiew:myInnerImageView];

回答by Anatoliy Gatt

You don't have the link between UIImageand UIImageViewquite right: you don't convertbetween them because one is the representation of the actual image and the other is the view that shows the image.

您没有链接之间UIImageUIImageView完全正确的:你不转换,因为一个是实际图像的表示,另一种是认为显示了图像之间。

A UIImageView object holds a reference to a UIImage object, allowing that image to be shown on the screen. Have a look at the UIImageView docs, and you will see that the class has a property image(the image that the UIImageView will show), and through this property you can access the UIImage contained within a UIImageView.

UIImageView 对象持有对 UIImage 对象的引用,允许该图像显示在屏幕上。查看UIImageView 文档,您将看到该类具有一个属性image(UIImageView 将显示的图像),通过此属性您可以访问包含在 UIImageView 中的 UIImage。

回答by jbat100

UIImageis an abstraction for image data, it doesn't display anything.

UIImage是图像数据的抽象,它不显示任何内容。

UIImageViewis a subclass of UIViewoptimized for displaying an image represented by UIImageonscreen.

UIImageViewUIView优化用于在UIImage屏幕上显示图像的子类。

To get the UIImageused by the UIImageView, use the image property.

要获取UIImage使用的UIImageView,请使用 image 属性。

回答by Hermann Klecker

UIImageView *theUIImageYouGot = some assignment made already;
CusstomImage *theUIImageSubclassYouWantToDisplay = [theUIImageYouGot image];