5. GIF File Conversion

Convert GIF files to watch face background files

Sample Code

//Get Gif transcoding object
GifConverter converter = GifConverter.getInstance();
//inputPath : Input file path (GIF file)
String inputPath = "Input file path (GIF file)";
//outputPath : Output file path (BIN file)
String outputPath = "Output file path (BIN file)";
//mode: Encoding mode
int mode = GifConverter.MODE_LOW_COMPRESSION_RATE; //Recommend low compression rate
// - GifConverter.MODE_LOW_COMPRESSION_RATE: Low compression rate
// - GifConverter.MODE_MEDIUM_COMPRESSION_RATE: Medium compression rate
// - GifConverter.MODE_HIGH_COMPRESSION_RATE: High compression rate
//V1.2.0+ Added, default value: GifConverter.CHIP_701N
int chip = GifConverter.CHIP_707N; //Select algorithm based on firmware chip
// - GifConverter.CHIP_701N : JL701N series chips
// - GifConverter.CHIP_707N : JL707N series chips
//V1.3.0+ Added, default value: true
boolean isPacketJLUI = true; //Whether to package as JL UI format; false, for raw data
//Execute GIF transcoding function
converter.gif2BinAsync(inputPath, outputPath, mode, chip, isPacketJLUI, new GifConverter.ResultCallback<GifBin>() {
    @Override
    public void onSuccess(GifBin gifBin) {
        //Transcoding success
        //gifBin --- GIF information
    }

    @Override
    public void onError(int code, String message) {
        //Transcoding failed
        //code --- Error code
        //message --- Description information
        }
});

Important

  1. Image conversion function requires importing library: GifConvert_Vxxx-release.aar

  2. Input image dimensions cannot exceed device screen size

  3. Input image size should be as small as possible

  4. GifBin

  5. ResultCallback

  6. Error Codes

5.1. GifBin

Gif transcoding file information

public class GifBin implements Parcelable {
    /**
     * Name
     */
    private String name;
    /**
     * Width
     */
    private int width;
    /**
     * Height
     */
    private int height;
    /**
     * Data
     */
    private byte[] data;
    /**
     * File path
     */
    private String path;
    /**
     * Whether to package in Jieli format
     */
    private boolean isPacket;
}

5.2. ResultCallback

Result callback

public interface ResultCallback<T> {

    /**
     * Callback successful result
     *
     * @param result Result
     */
    void onSuccess(T result);

    /**
     * Callback failure event
     *
     * @param code    Error code
     * @param message Error description
     */
    void onError(int code, String message);
}

5.3. Error Codes

  • Corresponding class name: GifError.java

  • Reference constants: GifError# xxx

Reference Constant

Code Value

Description

ERR_NONE

0

Operation successful

ERR_OPEN_FILE

1

Cannot open given file

ERR_WRITE_FAILED

2

Write data failed

ERR_HAS_SCRN_DSCR

3

Has SCRN DSCR

ERR_HAS_IMAG_DSCR

4

Has IMAG DSCR

ERR_NO_COLOR_MAP

5

Missing color table

ERR_DATA_TOO_BIG

6

Data too large

ERR_NOT_ENOUGH_MEM

7

Insufficient memory

ERR_DISK_IS_FULL

8

Disk is full

ERR_CLOSE_FAILED

9

Close file failed

ERR_NOT_WRITEABLE

10

No write attribute


ERR_D_OPEN_FILE

101

Cannot open given file

ERR_READ_FAILED

102

Cannot read file data

ERR_NOT_GIF_FILE

103

Not a GIF file

ERR_NO_SCRN_DSCR

104

Missing SCRN DSCR

ERR_NO_IMAG_DSCR

105

Missing IMAG DSCR

ERR_D_NO_COLOR_MAP

106

Missing color table

ERR_WRONG_RECORD

107

Wrong record

ERR_D_DATA_TOO_BIG

108

Data too large

ERR_D_NOT_ENOUGH_MEM

109

Insufficient memory

ERR_D_CLOSE_FAILED

110

Close file failed

ERR_NOT_READABLE

111

File not readable

ERR_IMAGE_DEFECT

112

Image detection failed

ERR_EOF_TOO_SOON

113

File ended too soon


ERR_INVALID_PARAM

301

Invalid parameter

ERR_OP_IN_PROGRESS

302

Operation in progress

ERR_SAVE_FILE

303

Save file failed


ERR_UNKNOWN_MODE

-128

Unknown compression mode

ERR_UNKNOWN_CHIP

-129

Unknown chip type