public static HeifImage ConvertToHeifImage(Image <Rgba32> image)
        {
            AnalyzeImage(image, out bool isGrayscale, out bool hasTransparency);

            var        colorspace = isGrayscale ? HeifColorspace.Monochrome : HeifColorspace.Rgb;
            HeifChroma chroma;

            if (colorspace == HeifColorspace.Monochrome)
            {
                chroma = HeifChroma.Monochrome;
            }
            else
            {
                chroma = hasTransparency ? HeifChroma.InterleavedRgba32 : HeifChroma.InterleavedRgb24;
            }

            HeifImage heifImage = null;
            HeifImage temp      = null;

            try
            {
                temp = new HeifImage(image.Width, image.Height, colorspace, chroma);

                if (colorspace == HeifColorspace.Monochrome)
                {
                    temp.AddPlane(HeifChannel.Y, image.Width, image.Height, 8);

                    if (hasTransparency)
                    {
                        temp.AddPlane(HeifChannel.Alpha, image.Width, image.Height, 8);
                    }

                    CopyGrayscale(image, temp, hasTransparency);
                }
                else
                {
                    temp.AddPlane(HeifChannel.Interleaved, image.Width, image.Height, 8);

                    CopyRgb(image, temp, hasTransparency);
                }

                heifImage = temp;
                temp      = null;
            }
            finally
            {
                temp?.Dispose();
            }

            return(heifImage);
        }
        public static HeifImage ConvertToHeifImage(Image <Rgb24> image)
        {
            bool isGrayscale = IsGrayscale(image);

            var colorspace = isGrayscale ? HeifColorspace.Monochrome : HeifColorspace.Rgb;
            var chroma     = colorspace == HeifColorspace.Monochrome ? HeifChroma.Monochrome : HeifChroma.InterleavedRgb24;

            HeifImage heifImage = null;
            HeifImage temp      = null;

            try
            {
                temp = new HeifImage(image.Width, image.Height, colorspace, chroma);

                if (colorspace == HeifColorspace.Monochrome)
                {
                    temp.AddPlane(HeifChannel.Y, image.Width, image.Height, 8);

                    CopyGrayscale(image, temp);
                }
                else
                {
                    temp.AddPlane(HeifChannel.Interleaved, image.Width, image.Height, 8);

                    CopyRgb(image, temp);
                }

                heifImage = temp;
                temp      = null;
            }
            finally
            {
                temp?.Dispose();
            }

            return(heifImage);
        }