Xwt.Drawing.Image.CreateMultiSizeIcon C# (CSharp) Method

CreateMultiSizeIcon() public static method

public static CreateMultiSizeIcon ( IEnumerable images ) : Image
images IEnumerable
return Image
        public static Image CreateMultiSizeIcon(IEnumerable<Image> images)
        {
            if (Toolkit.CurrentEngine == null)
                throw new ToolkitNotInitializedException ();

            var allImages = images.ToArray ();

            if (allImages.Length == 1)
                return allImages [0];

            if (allImages.Any (i => i is ThemedImage)) {
                // If one of the images is themed, then the whole resulting image will be themed.
                // To create the new image, we group images with the same theme but different size, and we create a multi-size icon for those.
                // The resulting image is the combination of those multi-size icons.
                var allThemes = allImages.OfType<ThemedImage> ().SelectMany (i => i.Images).Select (i => new ImageTagSet (i.Item2)).Distinct ().ToArray ();
                List<Tuple<Image, string []>> newImages = new List<Tuple<Image, string []>> ();
                foreach (var ts in allThemes) {
                    List<Image> multiSizeImages = new List<Image> ();
                    foreach (var i in allImages) {
                        if (i is ThemedImage)
                            multiSizeImages.Add (((ThemedImage)i).GetImage (ts.AsArray));
                        else
                            multiSizeImages.Add (i);
                    }
                    var img = CreateMultiSizeIcon (multiSizeImages);
                    newImages.Add (new Tuple<Image, string []> (img, ts.AsArray));
                }
                return new ThemedImage (newImages);
            } else {
                var img = new Image (Toolkit.CurrentEngine.ImageBackendHandler.CreateMultiSizeIcon (allImages.Select (ExtensionMethods.GetBackend)));

                if (allImages.All (i => i.NativeRef.HasNativeSource)) {
                    var sources = allImages.Select (i => i.NativeRef.NativeSource).ToArray ();
                    img.NativeRef.SetSources (sources);
                }
                return img;
            }
        }