Exemple #1
0
        private static BitmapDecoder GetDecoder(BitmapSource image, out GifFile gifFile)
        {
            gifFile = null;
            BitmapDecoder       decoder      = null;
            Stream              bitmapStream = null;
            Uri                 result       = null;
            BitmapCreateOptions none         = BitmapCreateOptions.None;
            BitmapImage         image2       = image as BitmapImage;

            if (image2 == null)
            {
                BitmapFrame frame = image as BitmapFrame;
                if (frame != null)
                {
                    decoder = frame.Decoder;
                    Uri.TryCreate(frame.BaseUri, frame.ToString(), out result);
                }
            }
            else
            {
                none = image2.CreateOptions;
                if (image2.StreamSource != null)
                {
                    bitmapStream = image2.StreamSource;
                }
                else if (image2.UriSource != null)
                {
                    result = image2.UriSource;
                    if ((image2.BaseUri != null) && !result.IsAbsoluteUri)
                    {
                        result = new Uri(image2.BaseUri, result);
                    }
                }
            }
            if (decoder == null)
            {
                if (bitmapStream != null)
                {
                    bitmapStream.Position = 0L;
                    decoder = BitmapDecoder.Create(bitmapStream, none, BitmapCacheOption.OnLoad);
                }
                else if ((result != null) && result.IsAbsoluteUri)
                {
                    decoder = BitmapDecoder.Create(result, none, BitmapCacheOption.OnLoad);
                }
            }
            if ((decoder is GifBitmapDecoder) && !CanReadNativeMetadata(decoder))
            {
                if (bitmapStream != null)
                {
                    bitmapStream.Position = 0L;
                    gifFile = GifFile.ReadGifFile(bitmapStream, true);
                }
                else if (result != null)
                {
                    gifFile = DecodeGifFile(result);
                }
            }
            return(decoder);
        }
Exemple #2
0
            private static Uri GetUri(ImageSource image)
            {
                BitmapImage image2 = image as BitmapImage;

                if ((image2 != null) && (image2.UriSource != null))
                {
                    if (image2.UriSource.IsAbsoluteUri)
                    {
                        return(image2.UriSource);
                    }
                    if (image2.BaseUri != null)
                    {
                        return(new Uri(image2.BaseUri, image2.UriSource));
                    }
                }
                BitmapFrame frame = image as BitmapFrame;

                if (frame != null)
                {
                    Uri    uri;
                    string uriString = frame.ToString();
                    if ((uriString != frame.GetType().FullName) && Uri.TryCreate(uriString, UriKind.RelativeOrAbsolute, out uri))
                    {
                        if (uri.IsAbsoluteUri)
                        {
                            return(uri);
                        }
                        if (frame.BaseUri != null)
                        {
                            return(new Uri(frame.BaseUri, uri));
                        }
                    }
                }
                return(null);
            }
        // Token: 0x06002DC6 RID: 11718 RVA: 0x000CDF38 File Offset: 0x000CC138
        public static FixedSOMImage Create(FixedPage page, Image image, FixedNode fixedNode)
        {
            Uri sourceUri = null;

            if (image.Source is BitmapImage)
            {
                BitmapImage bitmapImage = image.Source as BitmapImage;
                sourceUri = bitmapImage.UriSource;
            }
            else if (image.Source is BitmapFrame)
            {
                BitmapFrame bitmapFrame = image.Source as BitmapFrame;
                sourceUri = new Uri(bitmapFrame.ToString(), UriKind.RelativeOrAbsolute);
            }
            Rect             imageRect = new Rect(image.RenderSize);
            GeneralTransform trans     = image.TransformToAncestor(page);

            return(new FixedSOMImage(imageRect, trans, sourceUri, fixedNode, image));
        }
        // Token: 0x06002DC7 RID: 11719 RVA: 0x000CDFB0 File Offset: 0x000CC1B0
        public static FixedSOMImage Create(FixedPage page, Path path, FixedNode fixedNode)
        {
            ImageSource imageSource = ((ImageBrush)path.Fill).ImageSource;
            Uri         sourceUri   = null;

            if (imageSource is BitmapImage)
            {
                BitmapImage bitmapImage = imageSource as BitmapImage;
                sourceUri = bitmapImage.UriSource;
            }
            else if (imageSource is BitmapFrame)
            {
                BitmapFrame bitmapFrame = imageSource as BitmapFrame;
                sourceUri = new Uri(bitmapFrame.ToString(), UriKind.RelativeOrAbsolute);
            }
            Rect             bounds = path.Data.Bounds;
            GeneralTransform trans  = path.TransformToAncestor(page);

            return(new FixedSOMImage(bounds, trans, sourceUri, fixedNode, path));
        }
Exemple #5
0
        public static FixedSOMImage Create(FixedPage page, Path path, FixedNode fixedNode)
        {
            Debug.Assert(path.Fill is ImageBrush);
            ImageSource source   = ((ImageBrush)(path.Fill)).ImageSource;
            Uri         imageUri = null;

            if (source is BitmapImage)
            {
                BitmapImage imageSource = source as BitmapImage;
                imageUri = imageSource.UriSource;
            }
            else if (source is BitmapFrame)
            {
                BitmapFrame imageSource = source as BitmapFrame;
                imageUri = new Uri(imageSource.ToString(), UriKind.RelativeOrAbsolute);
            }

            Rect             sourceRect = path.Data.Bounds;
            GeneralTransform trans      = path.TransformToAncestor(page);

            return(new FixedSOMImage(sourceRect, trans, imageUri, fixedNode, path));
        }
        private static BitmapDecoder GetDecoder(BitmapSource image, Image imageControl, out GifFile gifFile)
        {
            gifFile = null;
            BitmapDecoder       decoder       = null;
            Stream              stream        = null;
            Uri                 uri           = null;
            BitmapCreateOptions createOptions = BitmapCreateOptions.None;

            var bmp = image as BitmapImage;

            if (bmp != null)
            {
                createOptions = bmp.CreateOptions;
                if (bmp.StreamSource != null)
                {
                    stream = bmp.StreamSource;
                }
                else if (bmp.UriSource != null)
                {
                    uri = bmp.UriSource;
                    if (!uri.IsAbsoluteUri)
                    {
                        var baseUri = bmp.BaseUri ?? (imageControl as IUriContext)?.BaseUri;
                        if (baseUri != null)
                        {
                            uri = new Uri(baseUri, uri);
                        }
                    }
                }
            }
            else
            {
                BitmapFrame frame = image as BitmapFrame;
                if (frame != null)
                {
                    decoder = frame.Decoder;
                    Uri.TryCreate(frame.BaseUri, frame.ToString(), out uri);
                }
            }

            if (decoder == null)
            {
                if (stream != null)
                {
                    stream.Position = 0;
                    decoder         = BitmapDecoder.Create(stream, createOptions, BitmapCacheOption.OnLoad);
                }
                else if (uri != null && uri.IsAbsoluteUri)
                {
                    decoder = BitmapDecoder.Create(uri, createOptions, BitmapCacheOption.OnLoad);
                }
            }

            if (decoder is GifBitmapDecoder && !CanReadNativeMetadata(decoder))
            {
                if (stream != null)
                {
                    stream.Position = 0;
                    gifFile         = GifFile.ReadGifFile(stream, true);
                }
                else if (uri != null)
                {
                    gifFile = DecodeGifFile(uri);
                }
                else
                {
                    throw new InvalidOperationException("Can't get URI or Stream from the source. AnimatedSource should be either a BitmapImage, or a BitmapFrame constructed from a URI.");
                }
            }
            if (decoder == null)
            {
                throw new InvalidOperationException("Can't get a decoder from the source. AnimatedSource should be either a BitmapImage or a BitmapFrame.");
            }
            return(decoder);
        }
        private static BitmapDecoder GetDecoder(BitmapSource image, out GifFile gifFile)
        {
            gifFile = null;
            BitmapDecoder       decoder       = null;
            Stream              stream        = null;
            Uri                 uri           = null;
            BitmapCreateOptions createOptions = BitmapCreateOptions.None;

            var bmp = image as BitmapImage;

            if (bmp != null)
            {
                createOptions = bmp.CreateOptions;
                if (bmp.StreamSource != null)
                {
                    stream = bmp.StreamSource;
                }
                else if (bmp.UriSource != null)
                {
                    uri = bmp.UriSource;
                    if (bmp.BaseUri != null && !uri.IsAbsoluteUri)
                    {
                        uri = new Uri(bmp.BaseUri, uri);
                    }
                }
            }
            else
            {
                BitmapFrame frame = image as BitmapFrame;
                if (frame != null)
                {
                    decoder = frame.Decoder;
                    Uri.TryCreate(frame.BaseUri, frame.ToString(), out uri);
                }
            }

            if (decoder == null)
            {
                if (stream != null)
                {
                    stream.Position = 0;
                    decoder         = BitmapDecoder.Create(stream, createOptions, BitmapCacheOption.OnLoad);
                }
                else if (uri != null && uri.IsAbsoluteUri)
                {
                    decoder = BitmapDecoder.Create(uri, createOptions, BitmapCacheOption.OnLoad);
                }
            }

            if (decoder is GifBitmapDecoder && !CanReadNativeMetadata(decoder))
            {
                if (stream != null)
                {
                    stream.Position = 0;
                    gifFile         = GifFile.ReadGifFile(stream, true);
                }
                else if (uri != null)
                {
                    gifFile = DecodeGifFile(uri);
                }
            }
            return(decoder);
        }