Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between UIImage and UIImageView

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

like image 715
ARC Avatar asked Nov 09 '11 19:11

ARC


People also ask

What is the difference between UIImage and UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

What is UIImage?

An object that manages image data in your app.

What is use of UIImageView?

Overview. Image views let you efficiently draw any image that can be specified using a UIImage object. For example, you can use the UIImageView class to display the contents of many standard image files, such as JPEG and PNG files.

How do I find my UIImage path?

Once a UIImage is created, the image data is loaded into memory and no longer connected to the file on disk. As such, the file can be deleted or modified without consequence to the UIImage and there is no way of getting the source path from a UIImage.

What is a UIImageView object?

An object that displays a single image or a sequence of animated images in your interface. Image views let you efficiently draw any image that can be specified using a UIImage object. For example, you can use the UIImageView class to display the contents of many standard image files, such as JPEG and PNG files.

Why does the background of an image show up in uiimage?

Any transparency in the image allows the image view’s background to show through. Similarly, any further transparency in the background of the image is dependent on the transparency of the image view and the transparency of the UIImage object it displays.

How to create a new UIImageView programmatically in Swift?

To create a new UIImageView programmatically in Swift, we need to create a new instance of UIImageView class and then set UIImage to an image property. Like so: The code snippet above creates a new instance of UIImageView and adds an image to it. However, it is not enough to make an image display.

What is the relationship between image transparency and uiimage transparency?

Similarly, any further transparency in the background of the image is dependent on the transparency of the image view and the transparency of the UIImage object it displays. When the image view and its image both have transparency, the image view uses alpha blending to combine the two.


Video Answer


2 Answers

Example:

UIImage *bgImage = [UIImage imageNamed:@"[email protected]"]; UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:bgImage]; backgroundImageView.frame = [[UIScreen mainScreen] bounds]; 

UIImage Overview:

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.

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.

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.

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 Overview:

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.

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.

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.

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

like image 183
chown Avatar answered Oct 05 '22 21:10

chown


UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage.

like image 36
Geekswordsman Avatar answered Oct 05 '22 23:10

Geekswordsman