【问题标题】:Converting UIImageView to UIImage将 UIImageView 转换为 UIImage
【发布时间】:2012-07-15 02:11:19
【问题描述】:

我正在处理图像,我有大量图像,我正在从服务器实时下载它们,在 AsyncImageView 类真的很快之前,但知道我正在使用自定义类,采用 UIImage 而不是 UIImageView。

问题:有没有什么好办法可以将UIImageView转换成UIImage?

提前致谢!

【问题讨论】:

  • 你必须有一个 UIImage 才能在 UIImageView 中显示它——问题出在哪里?
  • 不,我需要在 UIImage 中显示 UIImageView

标签: objective-c xcode uiimageview uikit uiimage


【解决方案1】:

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

UIImage *imageFromImageView = myImageView.image

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

[myOuterImageView addSubiew:myInnerImageView];

【讨论】:

    【解决方案2】:

    UIImage 和 UIImageView 之间的链接并不完全正确:您没有在它们之间转换,因为一个是实际图像的表示,另一个是视图显示图像。

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

    【讨论】:

      【解决方案3】:

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

      UIImageView 是UIView 的子类,针对在屏幕上显示由UIImage 表示的图像进行了优化。

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

      【讨论】:

        【解决方案4】:
        UIImageView *theUIImageYouGot = some assignment made already;
        CusstomImage *theUIImageSubclassYouWantToDisplay = [theUIImageYouGot image];
        

        【讨论】:

          猜你喜欢
          • 2018-04-01
          • 2013-06-16
          • 2013-10-13
          • 1970-01-01
          • 1970-01-01
          • 2012-07-03
          • 1970-01-01
          • 2015-07-30
          • 2013-01-01
          相关资源
          最近更新 更多