FromCustomLoader() public static méthode

public static FromCustomLoader ( IImageLoader loader, string fileName ) : Image
loader IImageLoader
fileName string
Résultat Image
Exemple #1
0
        public NativeImageRef LoadForToolkit(Toolkit targetToolkit)
        {
            if (Toolkit == targetToolkit)
            {
                return(this);
            }
            NativeImageRef newRef = null;
            var            r      = NextRef;

            while (r != this)
            {
                if (r.toolkit == targetToolkit)
                {
                    newRef = r;
                    break;
                }
                r = r.NextRef;
            }
            if (newRef != null)
            {
                return(newRef);
            }

            object newBackend = null;

            if (sources != null)
            {
                var frames = new List <object> ();
                foreach (var s in sources)
                {
                    if (s.ImageLoader != null)
                    {
                        var streams = s.ImageLoader();
                        try {
                            if (streams.Length == 1)
                            {
                                newBackend = targetToolkit.ImageBackendHandler.LoadFromStream(streams [0]);
                            }
                            else
                            {
                                var backends = new object [streams.Length];
                                for (int n = 0; n < backends.Length; n++)
                                {
                                    backends [n] = targetToolkit.ImageBackendHandler.LoadFromStream(streams [n]);
                                }
                                newBackend = targetToolkit.ImageBackendHandler.CreateMultiResolutionImage(backends);
                            }
                        } finally {
                            foreach (var st in streams)
                            {
                                st.Dispose();
                            }
                        }
                    }
                    else if (s.CustomImageLoader != null)
                    {
                        targetToolkit.Invoke(() => newBackend = Image.FromCustomLoader(s.CustomImageLoader, s.Source, s.Tags).GetBackend());
                    }
                    else if (s.ResourceAssembly != null)
                    {
                        targetToolkit.Invoke(() => newBackend = Image.FromResource(s.ResourceAssembly, s.Source).GetBackend());
                    }
                    else if (s.Source != null)
                    {
                        targetToolkit.Invoke(() => newBackend = Image.FromFile(s.Source).GetBackend());
                    }
                    else if (s.DrawCallback != null)
                    {
                        newBackend = targetToolkit.ImageBackendHandler.CreateCustomDrawn(s.DrawCallback);
                    }
                    else if (s.StockId != null)
                    {
                        newBackend = targetToolkit.GetStockIcon(s.StockId).GetBackend();
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                    frames.Add(newBackend);
                }
                newBackend = targetToolkit.ImageBackendHandler.CreateMultiSizeIcon(frames);
            }
            else
            {
                using (var s = new MemoryStream()) {
                    toolkit.ImageBackendHandler.SaveToStream(backend, s, ImageFileType.Png);
                    s.Position = 0;
                    newBackend = targetToolkit.ImageBackendHandler.LoadFromStream(s);
                }
            }
            newRef         = new NativeImageRef(newBackend, targetToolkit);
            newRef.NextRef = NextRef;
            NextRef        = newRef;
            return(newRef);
        }