UIImage(MultiFormat)

@interface UIImage (MultiFormat)

UIImage category for convenient image format decoding/encoding.

Decode

  • Create and decode a image with the specify image data

    Declaration

    Objective-C

    + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data;

    Swift

    class func sd_image(with data: Data?) -> UIImage?

    Parameters

    data

    The image data

    Return Value

    The created image

  • Create and decode a image with the specify image data and scale

    Declaration

    Objective-C

    + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data
                                     scale:(CGFloat)scale;

    Swift

    class func sd_image(with data: Data?, scale: CGFloat) -> UIImage?

    Parameters

    data

    The image data

    scale

    The image scale factor. Should be greater than or equal to 1.0.

    Return Value

    The created image

  • Create and decode a image with the specify image data and scale, allow specify animate/static control

    Declaration

    Objective-C

    + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data
                                     scale:(CGFloat)scale
                            firstFrameOnly:(BOOL)firstFrameOnly;

    Swift

    class func sd_image(with data: Data?, scale: CGFloat, firstFrameOnly: Bool) -> UIImage?

    Parameters

    data

    The image data

    scale

    The image scale factor. Should be greater than or equal to 1.0.

    firstFrameOnly

    Even if the image data is animated image format, decode the first frame only as static image.

    Return Value

    The created image

Encode

  • Encode the current image to the data, the image format is unspecified

    Note

    If the receiver is SDAnimatedImage, this will return the animated image data if available. No more extra encoding process.

    Declaration

    Objective-C

    - (nullable NSData *)sd_imageData;

    Swift

    func sd_imageData() -> Data?

    Return Value

    The encoded data. If can’t encode, return nil

  • Encode the current image to data with the specify image format

    Declaration

    Objective-C

    - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat;

    Swift

    func sd_imageData(as imageFormat: SDImageFormat) -> Data?

    Parameters

    imageFormat

    The specify image format

    Return Value

    The encoded data. If can’t encode, return nil

  • Encode the current image to data with the specify image format and compression quality

    Declaration

    Objective-C

    - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat
                           compressionQuality:(double)compressionQuality;

    Swift

    func sd_imageData(as imageFormat: SDImageFormat, compressionQuality: Double) -> Data?

    Parameters

    imageFormat

    The specify image format

    compressionQuality

    The quality of the resulting image data. Value between 0.0-1.0. Some coders may not support compression quality.

    Return Value

    The encoded data. If can’t encode, return nil

  • Encode the current image to data with the specify image format and compression quality, allow specify animate/static control

    Declaration

    Objective-C

    - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat
                           compressionQuality:(double)compressionQuality
                               firstFrameOnly:(BOOL)firstFrameOnly;

    Swift

    func sd_imageData(as imageFormat: SDImageFormat, compressionQuality: Double, firstFrameOnly: Bool) -> Data?

    Parameters

    imageFormat

    The specify image format

    compressionQuality

    The quality of the resulting image data. Value between 0.0-1.0. Some coders may not support compression quality.

    firstFrameOnly

    Even if the image is animated image, encode the first frame only as static image.

    Return Value

    The encoded data. If can’t encode, return nil