Function

UIImagePNGRepresentation(_:)

Returns the data for the specified image in PNG format

Declaration

func UIImagePNGRepresentation(_ image: UIImage) -> Data?

Parameters

image

The original image data.

Return Value

A data object containing the PNG data, or nil if there was a problem generating the data. This function may return nil if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.

Discussion

If the image object’s underlying image data has been purged, calling this function forces that data to be reloaded into memory.

See Also

Image Creation

func UIGraphicsBeginImageContext(CGSize)

Creates a bitmap-based graphics context and makes it the current context.

func UIGraphicsGetImageFromCurrentImageContext()

Returns an image based on the contents of the current bitmap-based graphics context.

func UIGraphicsEndImageContext()

Removes the current bitmap-based graphics context from the top of the stack.

func UIImageJPEGRepresentation(UIImage, CGFloat)

Returns the data for the specified image in JPEG format.