UIImage和UIImageView之间的区别 [英] Difference between UIImage and UIImageView

查看:106
本文介绍了UIImage和UIImageView之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIImageUIImageView有什么区别?有人可以举例说明吗?

What is the difference between UIImage and UIImageView? Can someone explain it with an example?

推荐答案

示例:

UIImage *bgImage = [UIImage imageNamed:@"Default@2x.png"];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:bgImage];
backgroundImageView.frame = [[UIScreen mainScreen] bounds];

UIImage概述:

UIImage对象是显示图像数据的高级方法.你可以 从文件,Quartz图像对象或原始图像创建图像 您收到的数据. UIImage类还为 使用不同的混合将图像绘制到当前图形上下文 模式和不透明度值.

A UIImage object is a high-level way to display image data. You can create images from files, from Quartz image objects, or from raw image data you receive. The UIImage class also offers several options for drawing images to the current graphics context using different blend modes and opacity values.

图像对象是不可变的,因此您不能更改其属性 创建后.这意味着您通常会指定图片的 属性在初始化时还是依靠图片的元数据 提供属性值.但是,在某些情况下,UIImage类 提供了方便的方法来获取图像的副本, 使用属性的自定义值.

Image objects are immutable, so you cannot change their properties after creation. This means that you generally specify an image’s properties at initialization time or rely on the image’s metadata to provide the property value. In some cases, however, the UIImage class provides convenience methods for obtaining a copy of the image that uses custom values for a property.

由于图像对象是不可变的,因此它们也不提供直接 访问其基础图像数据.但是,您可以获得一个NSData 包含图像的PNG或JPEG表示形式的对象 UIImagePNGRepresentationUIImageJPEGRepresentation使用数据 功能.

Because image objects are immutable, they also do not provide direct access to their underlying image data. However, you can get an NSData object containing either a PNG or JPEG representation of the image data using the UIImagePNGRepresentation and UIImageJPEGRepresentation functions.

系统使用图像对象来表示用 相机在支持的设备上.要拍照,请使用 UIImagePickerController类.将图片保存到保存的照片"中 专辑,请使用UIImageWriteToSavedPhotosAlbum功能.

The system uses image objects to represent still pictures taken with the camera on supported devices. To take a picture, use the UIImagePickerController class. To save a picture to the Saved Photos album, use the UIImageWriteToSavedPhotosAlbum function.

UIImageView概述:

UIImageView提供用于显示的基于视图的容器 要么是单个图像,要么是一系列图像的动画.为了 对图像进行动画处理,UIImageView类提供了用于设置图像的控件 动画的持续时间和频率.您也可以启动和 自由地停止动画.

An UIImageView provides a view-based container for displaying either a single image or for animating a series of images. For animating the images, the UIImageView class provides controls to set the duration and frequency of the animation. You can also start and stop the animation freely.

新的图像视图对象配置为通过以下方式忽略用户事件: 默认.如果您要处理的自定义子类中的事件 UIImageView,您必须显式更改 初始化对象后,将userInteractionEnabled属性设置为YES.

New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.

UIImageView对象显示其图像之一时,实际 行为基于图像和视图的属性.如果 图片的leftCapWidthtopCapHeight属性是 非零,然后根据那些值拉伸图像 特性.否则,图像将被缩放,调整大小以适合或 根据的contentMode属性位于图像视图中 风景.建议(但不是必需)使用图像 都一样大小.如果图像大小不同,则每个 将根据该模式进行调整以单独适应.

When a UIImageView object displays one of its images, the actual behavior is based on the properties of the image and the view. If either of the image’s leftCapWidth or topCapHeight properties are non-zero, then the image is stretched according to the values in those properties. Otherwise, the image is scaled, sized to fit, or positioned in the image view according to the contentMode property of the view. It is recommended (but not required) that you use images that are all the same size. If the images are different sizes, each will be adjusted to fit separately based on that mode.

UIImageView对象关联的所有图像均应使用相同的图像 规模.如果您的应用程序使用不同比例的图像,它们可能 呈现不正确.

All images associated with a UIImageView object should use the same scale. If your application uses images with different scales, they may render incorrectly.

这篇关于UIImage和UIImageView之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆