Tuya iOS Smart Life App SDK 5.15.0
ThingEncryptImageEncoder Class Reference

#import <ThingEncryptImageCoder.h>

Inheritance diagram for ThingEncryptImageEncoder:

Instance Methods

(instancetype) - UNAVAILABLE_ATTRIBUTE
 
(nullable instancetype) - initWithType:
 
(void) - addImage:duration:
 
(void) - addImageWithData:duration:
 
(void) - addImageWithFile:duration:
 
(nullable NSData *) - encode
 
(BOOL) - encodeToFile:
 
(instancetype) - UNAVAILABLE_ATTRIBUTE
 
(nullable instancetype) - initWithType:
 
(void) - addImage:duration:
 
(void) - addImageWithData:duration:
 
(void) - addImageWithFile:duration:
 
(nullable NSData *) - encode
 
(BOOL) - encodeToFile:
 
(instancetype) - UNAVAILABLE_ATTRIBUTE
 
(nullable instancetype) - initWithType:
 
(void) - addImage:duration:
 
(void) - addImageWithData:duration:
 
(void) - addImageWithFile:duration:
 
(nullable NSData *) - encode
 
(BOOL) - encodeToFile:
 
(instancetype) - UNAVAILABLE_ATTRIBUTE
 
(nullable instancetype) - initWithType:
 
(void) - addImage:duration:
 
(void) - addImageWithData:duration:
 
(void) - addImageWithFile:duration:
 
(nullable NSData *) - encode
 
(BOOL) - encodeToFile:
 

Class Methods

(instancetype) + UNAVAILABLE_ATTRIBUTE
 
(nullable NSData *) + encodeImage:type:quality:
 
(nullable NSData *) + encodeImageWithDecoder:type:quality:
 
(instancetype) + UNAVAILABLE_ATTRIBUTE
 
(nullable NSData *) + encodeImage:type:quality:
 
(nullable NSData *) + encodeImageWithDecoder:type:quality:
 
(instancetype) + UNAVAILABLE_ATTRIBUTE
 
(nullable NSData *) + encodeImage:type:quality:
 
(nullable NSData *) + encodeImageWithDecoder:type:quality:
 
(instancetype) + UNAVAILABLE_ATTRIBUTE
 
(nullable NSData *) + encodeImage:type:quality:
 
(nullable NSData *) + encodeImageWithDecoder:type:quality:
 

Properties

ThingEncryptImageType type
 Image type. More...
 
NSUInteger loopCount
 Loop count, 0 means infinit, only available for GIF/APNG/WebP. More...
 
BOOL lossless
 Lossless, only available for WebP. More...
 
CGFloat quality
 Compress quality, 0.0~1.0, only available for JPG/JP2/WebP. More...
 

Detailed Description

An image encoder to encode image to data.

@discussion It supports encoding single frame image with the type defined in ThingImageType. It also supports encoding multi-frame image with GIF, APNG and WebP.

Example:

ThingImageEncoder *jpegEncoder = [[ThingImageEncoder alloc] initWithType:ThingImageTypeJPEG]; jpegEncoder.quality = 0.9; [jpegEncoder addImage:image duration:0]; NSData jpegData = [jpegEncoder encode];

ThingImageEncoder *gifEncoder = [[ThingImageEncoder alloc] initWithType:ThingImageTypeGIF]; gifEncoder.loopCount = 5; [gifEncoder addImage:image0 duration:0.1]; [gifEncoder addImage:image1 duration:0.15]; [gifEncoder addImage:image2 duration:0.2]; NSData gifData = [gifEncoder encode];

Warning
It just pack the images together when encoding multi-frame image. If you want to reduce the image file size, try imagemagick/ffmpeg for GIF and WebP, and apngasm for APNG.

Definition at line 214 of file ThingEncryptImageCoder.h.

Method Documentation

◆ addImage:duration: [1/4]

- (void) addImage: (UIImage *)  image
duration: (NSTimeInterval)  duration 

Add an image to encoder.

Parameters
imageImage.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImage:duration: [2/4]

- (void) addImage: (UIImage *)  image
duration: (NSTimeInterval)  duration 

Add an image to encoder.

Parameters
imageImage.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImage:duration: [3/4]

- (void) addImage: (UIImage *)  image
duration: (NSTimeInterval)  duration 

Add an image to encoder.

Parameters
imageImage.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImage:duration: [4/4]

- (void) addImage: (UIImage *)  image
duration: (NSTimeInterval)  duration 

Add an image to encoder.

Parameters
imageImage.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithData:duration: [1/4]

- (void) addImageWithData: (NSData *)  data
duration: (NSTimeInterval)  duration 

Add an image with image data to encoder.

Parameters
dataImage data.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithData:duration: [2/4]

- (void) addImageWithData: (NSData *)  data
duration: (NSTimeInterval)  duration 

Add an image with image data to encoder.

Parameters
dataImage data.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithData:duration: [3/4]

- (void) addImageWithData: (NSData *)  data
duration: (NSTimeInterval)  duration 

Add an image with image data to encoder.

Parameters
dataImage data.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithData:duration: [4/4]

- (void) addImageWithData: (NSData *)  data
duration: (NSTimeInterval)  duration 

Add an image with image data to encoder.

Parameters
dataImage data.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithFile:duration: [1/4]

- (void) addImageWithFile: (NSString *)  path
duration: (NSTimeInterval)  duration 

Add an image from a file path to encoder.

Parameters
pathImage file path.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithFile:duration: [2/4]

- (void) addImageWithFile: (NSString *)  path
duration: (NSTimeInterval)  duration 

Add an image from a file path to encoder.

Parameters
pathImage file path.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithFile:duration: [3/4]

- (void) addImageWithFile: (NSString *)  path
duration: (NSTimeInterval)  duration 

Add an image from a file path to encoder.

Parameters
pathImage file path.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ addImageWithFile:duration: [4/4]

- (void) addImageWithFile: (NSString *)  path
duration: (NSTimeInterval)  duration 

Add an image from a file path to encoder.

Parameters
pathImage file path.
durationImage duration for animation. Pass 0 to ignore this parameter.

◆ encode [1/4]

- (nullable NSData *) encode

Encodes the image and returns the image data.

Returns
The image data, or nil if an error occurs.

◆ encode [2/4]

- (nullable NSData *) encode

Encodes the image and returns the image data.

Returns
The image data, or nil if an error occurs.

◆ encode [3/4]

- (nullable NSData *) encode

Encodes the image and returns the image data.

Returns
The image data, or nil if an error occurs.

◆ encode [4/4]

- (nullable NSData *) encode

Encodes the image and returns the image data.

Returns
The image data, or nil if an error occurs.

◆ encodeImage:type:quality: [1/4]

+ (nullable NSData *) encodeImage: (UIImage *)  image
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode single frame image.

Parameters
imageThe image.
typeThe destination image type.
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeImage:type:quality: [2/4]

+ (nullable NSData *) encodeImage: (UIImage *)  image
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode single frame image.

Parameters
imageThe image.
typeThe destination image type.
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeImage:type:quality: [3/4]

+ (nullable NSData *) encodeImage: (UIImage *)  image
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode single frame image.

Parameters
imageThe image.
typeThe destination image type.
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeImage:type:quality: [4/4]

+ (nullable NSData *) encodeImage: (UIImage *)  image
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode single frame image.

Parameters
imageThe image.
typeThe destination image type.
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeImageWithDecoder:type:quality: [1/4]

+ (nullable NSData *) encodeImageWithDecoder: (ThingEncryptImageDecoder *)  decoder
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode image from a decoder.

Parameters
decoderThe image decoder.
typeThe destination image type;
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeImageWithDecoder:type:quality: [2/4]

+ (nullable NSData *) encodeImageWithDecoder: (ThingEncryptImageDecoder *)  decoder
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode image from a decoder.

Parameters
decoderThe image decoder.
typeThe destination image type;
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeImageWithDecoder:type:quality: [3/4]

+ (nullable NSData *) encodeImageWithDecoder: (ThingEncryptImageDecoder *)  decoder
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode image from a decoder.

Parameters
decoderThe image decoder.
typeThe destination image type;
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeImageWithDecoder:type:quality: [4/4]

+ (nullable NSData *) encodeImageWithDecoder: (ThingEncryptImageDecoder *)  decoder
type: (ThingEncryptImageType)  type
quality: (CGFloat)  quality 

Convenience method to encode image from a decoder.

Parameters
decoderThe image decoder.
typeThe destination image type;
qualityImage quality, 0.0~1.0.
Returns
The image data, or nil if an error occurs.

◆ encodeToFile: [1/4]

- (BOOL) encodeToFile: (NSString *)  path

Encodes the image to a file.

Parameters
pathThe file path (overwrite if exist).
Returns
Whether succeed.

◆ encodeToFile: [2/4]

- (BOOL) encodeToFile: (NSString *)  path

Encodes the image to a file.

Parameters
pathThe file path (overwrite if exist).
Returns
Whether succeed.

◆ encodeToFile: [3/4]

- (BOOL) encodeToFile: (NSString *)  path

Encodes the image to a file.

Parameters
pathThe file path (overwrite if exist).
Returns
Whether succeed.

◆ encodeToFile: [4/4]

- (BOOL) encodeToFile: (NSString *)  path

Encodes the image to a file.

Parameters
pathThe file path (overwrite if exist).
Returns
Whether succeed.

◆ initWithType: [1/4]

- (nullable instancetype) initWithType: (ThingEncryptImageType)  NS_DESIGNATED_INITIALIZER

Create an image encoder with a specified type.

Parameters
typeImage type.
Returns
A new encoder, or nil if an error occurs.

◆ initWithType: [2/4]

- (nullable instancetype) initWithType: (ThingEncryptImageType)  NS_DESIGNATED_INITIALIZER

Create an image encoder with a specified type.

Parameters
typeImage type.
Returns
A new encoder, or nil if an error occurs.

◆ initWithType: [3/4]

- (nullable instancetype) initWithType: (ThingEncryptImageType)  NS_DESIGNATED_INITIALIZER

Create an image encoder with a specified type.

Parameters
typeImage type.
Returns
A new encoder, or nil if an error occurs.

◆ initWithType: [4/4]

- (nullable instancetype) initWithType: (ThingEncryptImageType)  NS_DESIGNATED_INITIALIZER

Create an image encoder with a specified type.

Parameters
typeImage type.
Returns
A new encoder, or nil if an error occurs.

◆ UNAVAILABLE_ATTRIBUTE [1/8]

+ (instancetype) UNAVAILABLE_ATTRIBUTE

◆ UNAVAILABLE_ATTRIBUTE [2/8]

- (instancetype) UNAVAILABLE_ATTRIBUTE

◆ UNAVAILABLE_ATTRIBUTE [3/8]

+ (instancetype) UNAVAILABLE_ATTRIBUTE

◆ UNAVAILABLE_ATTRIBUTE [4/8]

- (instancetype) UNAVAILABLE_ATTRIBUTE

◆ UNAVAILABLE_ATTRIBUTE [5/8]

+ (instancetype) UNAVAILABLE_ATTRIBUTE

◆ UNAVAILABLE_ATTRIBUTE [6/8]

- (instancetype) UNAVAILABLE_ATTRIBUTE

◆ UNAVAILABLE_ATTRIBUTE [7/8]

+ (instancetype) UNAVAILABLE_ATTRIBUTE

◆ UNAVAILABLE_ATTRIBUTE [8/8]

- (instancetype) UNAVAILABLE_ATTRIBUTE

Property Documentation

◆ loopCount

- (NSUInteger) loopCount
readwritenonatomicassign

Loop count, 0 means infinit, only available for GIF/APNG/WebP.

Definition at line 217 of file ThingEncryptImageCoder.h.

◆ lossless

- (BOOL) lossless
readwritenonatomicassign

Lossless, only available for WebP.

Definition at line 218 of file ThingEncryptImageCoder.h.

◆ quality

- (CGFloat) quality
readwritenonatomicassign

Compress quality, 0.0~1.0, only available for JPG/JP2/WebP.

Definition at line 219 of file ThingEncryptImageCoder.h.

◆ type

- (ThingEncryptImageType) type
readnonatomicassign

Image type.

Definition at line 216 of file ThingEncryptImageCoder.h.


The documentation for this class was generated from the following files: