GifEncoderEncodeHighColorImage Method
Encodes the specified imageData as a multi-layered, single frame GIF image and writes it into the specified stream, preserving its original color depth.
Namespace: KGySoft.Drawing.ImagingAssembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.2.0
public static void EncodeHighColorImage(
IReadableBitmapData imageData,
Stream stream,
bool allowFullScan = false,
Color32 backColor = default,
byte alphaThreshold = 128
)
Public Shared Sub EncodeHighColorImage (
imageData As IReadableBitmapData,
stream As Stream,
Optional allowFullScan As Boolean = false,
Optional backColor As Color32 = Nothing,
Optional alphaThreshold As Byte = 128
)
public:
static void EncodeHighColorImage(
IReadableBitmapData^ imageData,
Stream^ stream,
bool allowFullScan = false,
Color32 backColor = Color32(),
unsigned char alphaThreshold = 128
)
static member EncodeHighColorImage :
imageData : IReadableBitmapData *
stream : Stream *
?allowFullScan : bool *
?backColor : Color32 *
?alphaThreshold : byte
(* Defaults:
let _allowFullScan = defaultArg allowFullScan false
let _backColor = defaultArg backColor new Color32()
let _alphaThreshold = defaultArg alphaThreshold 128
*)
-> unit
Parameters
- imageData IReadableBitmapData
- The image data to write. Possible alpha pixels might be blended with backColor but otherwise the color depth will be preserved.
- stream Stream
- The stream to save the encoded animation into.
- allowFullScan Boolean (Optional)
- to allow scanning the whole image for each layers to be able to re-use the local palette of the current layer.
to expand the initial layer area to the local pixels only. This parameter is optional.
Default value: . - backColor Color32 (Optional)
- Colors with alpha (transparency), whose Color32.A field
is equal to or greater than alphaThreshold will be blended with this color during the encoding.
The alpha value (Color32.A field) of the specified background color is ignored. This parameter is optional.
Default value: The default value of the Color32 type, which has the same RGB values as Black. - alphaThreshold Byte (Optional)
- Specifies a threshold value for the Color32.A field, under which a pixel is considered transparent.
If 0, then the final composite image will not have transparent pixels. This parameter is optional.
Default value: 128.
This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation or reporting progress. Use the
BeginEncodeHighColorImage
or
EncodeHighColorImageAsync (in .NET Framework 4.0 and above) methods for asynchronous call and to set up cancellation or for reporting progress.
This method produces a GIF image that may have compatibility issues. Though the
Image
and
Bitmap types (at least on Windows)
support them as expected as well as applications built on GDI+ (such as Windows Paint), many decoders may treat the result as an animation (including browsers).
If allowFullScan is , then both the processing time and memory usage is higher.
It helps to minimize the number of layers of the final image; however, the final image size will not be necessarily smaller, especially for true color images.
If allowFullScan is , then each layer is attempted to be as compact as possible. It allows a very fast processing with lower memory usage.
Though it usually produces more layers, the final size will not be necessarily larger, especially for true color images.
You can prequantize true color images using a 16-bit quantizer (with or without dithering) to produce fairly compact, still high color GIF images.
For such images the
allowFullScan parameter with
value typically produces more compact results.
You can consider using the
Argb1555 quantizer for images with transparency,
or the
Rgb565 quantizer for non-transparent images.
To encode an Image you can use also the ImageExtensions.SaveAsHighColorGif methods.
To create a multi-layered image completely manually you can create a GifEncoder instance that provides a lower level access.