Converting UIImageView to UIImage

2019-02-25 03:53发布

问题:

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 AsyncImageView class, but know I'm working with the custom class, that takes UIImage instead of UIImageView.

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

Thanks in advance!

回答1:

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 *imageFromImageView = myImageView.image

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

[myOuterImageView addSubiew:myInnerImageView];


回答2:

You don't have the link between UIImage and UIImageView quite right: you don't convert between them because one is the representation of the actual image and the other is the view that shows the image.

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.



回答3:

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

UIImageView is a subclass of UIView optimized for displaying an image represented by UIImage onscreen.

To get the UIImage used by the UIImageView, use the image property.



回答4:

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