Translations: 简体中文
Decoder is used to decode image files. Each supported image type has a corresponding Decoder implementation, as shown in the following table:
Format | Decoder | Dependent modules | Android | iOS | Desktop | Web |
---|---|---|---|---|---|---|
jpeg | BitmapFactoryDecoder | - | ✅ | ❌ | ❌ | ❌ |
jpeg | SkiaDecoder | - | ❌ | ✅ | ✅ | ✅ |
png | BitmapFactoryDecoder | - | ✅ | ❌ | ❌ | ❌ |
png | SkiaDecoder | - | ❌ | ✅ | ✅ | ✅ |
webp | BitmapFactoryDecoder | - | ✅ | ❌ | ❌ | ❌ |
webp | SkiaDecoder | - | ❌ | ✅ | ✅ | ✅ |
bmp | BitmapFactoryDecoder | - | ✅ | ❌ | ❌ | ❌ |
bmp | SkiaDecoder | - | ❌ | ✅ | ✅ | ✅ |
heif | BitmapFactoryDecoder | - | ✅ (API 28) | ❌ | ❌ | ❌ |
avif | BitmapFactoryDecoder | - | ✅ (API 31) | ❌ | ❌ | ❌ |
gif | ImageDecoderGifDecoder | sketch-animated-gif | ✅ (API 28) | ❌ | ❌ | ❌ |
gif | MovieGifDecoder (Not Support resize) |
sketch-animated-gif | ✅ | ❌ | ❌ | ❌ |
gif | SkiaGifDecoder (Not Support resize) |
sketch-animated-gif | ✅ | ❌ | ❌ | ❌ |
gif | KoralGifDecoder | sketch-animated-gif-koral | ❌ | ✅ | ✅ | ✅ |
Animated webp | ImageDecoderAnimatedWebpDecoder | sketch-animated-webp | ✅ (API 28) | ❌ | ❌ | ❌ |
Animated webp | SkiaAnimatedWebpDecoder (Not Support resize) |
sketch-animated-webp | ❌ | ✅ | ✅ | ✅ |
Animated heif | ImageDecoderAnimatedHeifDecoder | sketch-animated-heif | ✅ (API 30) | ❌ | ❌ | ❌ |
svg | SvgDecoder | sketch-svg | ✅ | ✅ (Not Support CSS) |
✅ (Not Support CSS) |
✅ (Not Support CSS) |
Video frames | VideoFrameDecoder | sketch-video | ✅ | ❌ | ❌ | ❌ |
Video frames | FFmpegVideoFrameDecoder | sketch-video-ffmpeg | ✅ | ❌ | ❌ | ❌ |
Apk Icon | ApkIconDecoder | sketch-extensions-core | ✅ | ❌ | ❌ | ❌ |
- ApkIconDecoder Decoding the icon of an Apk file on Android (Learn more)
- BitmapFactoryDecoder Decode images on the Android platform using Android's built-in BitmapFactory, which is the last resort decoder
- DrawableDecoder Decode vector, shape and other xml drawable images supported by Android on the Android platform
- ImageDecoderGifDecoder Use Android's built-in ImageDecoder to decode gif animations on the Android platform (Learn more)
- KoralGifDecoder Use koral--'s android-gif-drawable library to decode animated gifs on the Android platform (Learn more)
- MovieGifDecoder Use Android's built-in Movie to decode gif animations on the Android platform (Learn more)
- SkiaGifDecoder Use Skia's built-in Codec to decode gif animations on non-Android platforms (Learn more)
- ImageDecoderAnimatedHeifDecoder Use Android's built-in ImageDecoder to decode heif animations (Learn more)
- SkiaDecoder Use Skia's built-in Image to decode images on non-Android platforms, which is the last decoder* SvgDecoder Use BigBadaboom's androidsvg library on Android platforms, and use Skia's built-in SVGDOM to decode static svg files on non-Android platforms ( Learn more)
- ImageDecoderAnimatedWebpDecoder Use Android's built-in ImageDecoder to decode webp animations on the Android platform (Learn more)
- SkiaAnimatedWebpDecoder Use Skia's built-in Codec to decode webp animations on non-Android platforms (Learn more)
- VideoFrameDecoder Decode frames of video files using Android's built-in MediaMetadataRetriever class on the Android platform (Learn more)
- FFmpegVideoFrameDecoder Decoding video frames using wseemann's FFmpegMediaMetadataRetriever library on Android (Learn more)
Important
The above components all support automatic registration. You only need to import them without additional configuration. If you need to register manually, please read the documentation: 《Register component》
First implement the Decoder interface to define your Decoder and its Factory
Then refer to the document 《Register component》 to register your Decoder.
Caution
- Customizing Decoder requires applying many properties related to image quality and size in ImageRequest, such as size, colorType, colorSpace, etc. You can refer to other Decoder implementations
- If your Decoder is decoding animated images, you must determine the ImageRequest .disallowAnimatedImage parameter.
BitmapColorType is used to set the color type of the bitmap. The optional values are:
- FixedColorType: always use the specified color type
- LowQualityColorType: Prioritize low-quality color types
- jpeg images on the Android platform use RGB_565, and other values use the default value.
- jpeg and webp images on non-Android platforms use RGB_565, others use ARGB_4444
- HighQualityColorType: Give priority to high-quality color types
- On the Android platform, API 26 and above use RGBA_F16, and others use the default value.
- Always use RGBA_F16 on non-Android platforms
Example:
ImageRequest(context, "https://example.com/image.jpg") {
// Use specified color type on Android platform
colorType(Bitmap.Config.RGB_565)
// Use specified color type on non-Android platforms
colorType(ColorType.RGBA_F16)
// Prioritize lower quality color types
colorType(LowQualityColorType)
// Prioritize high-quality color types
colorType(HighQualityColorType)
}
BitmapColorSpace is used to set the color space of the bitmap. The optional values are:
- FixedColorSpace: Always use the specified color space
Example:
ImageRequest(context, "https://example.com/image.jpg") {
// Use specified color space on Android platform
colorSpace(ColorSpace.Named.DISPLAY_P3)
// Use specified color space on non-Android platforms
colorSpace(ColorSpace.displayP3)
}
preferQualityOverSpeed is used to set quality priority when decoding. It can only be used on the Android platform.
Example:
ImageRequest(context, "https://example.com/image.jpg") {
preferQualityOverSpeed(true)
}