public WpfRenderImageSource(wpf::System.Windows.Media.Imaging.BitmapImage bitmapImage)
        {
            this.BitmapImage = bitmapImage;

            BitmapImage.DownloadProgress  += (sender, e) => State = RenderImageState.DownloadProgress;
            BitmapImage.DownloadFailed    += (sender, e) => State = RenderImageState.DownloadFailed;
            BitmapImage.DownloadCompleted += (sender, e) =>
            {
                Size  = new Size(BitmapImage.PixelWidth, BitmapImage.PixelHeight);
                State = RenderImageState.DownloadCompleted;
            };

            Size = new Size(BitmapImage.PixelWidth, BitmapImage.PixelHeight);
        }
        public IRenderImageSource CreateRenderImageSource(RenderImageType imageType, byte[] data, Rect sourceRect)
        {
            wpf::System.Windows.Media.Imaging.BitmapImage bitmapImage = new wpf::System.Windows.Media.Imaging.BitmapImage();

            bitmapImage.BeginInit();
            bitmapImage.StreamSource = new MemoryStream(data);

            if (!sourceRect.IsNullOrEmpty())
            {
                bitmapImage.SourceRect = new wpf::System.Windows.Int32Rect((int)sourceRect.Left, (int)sourceRect.Top, (int)sourceRect.Width, (int)sourceRect.Height);
            }

            bitmapImage.EndInit();

            return(new WpfRenderImageSource(bitmapImage));
        }
        public IRenderImageSource CreateRenderImageSource(Uri uri, Rect sourceRect)
        {
            if (uri.GetScheme() != "http" && uri.GetScheme() != "https")
            {
                return(CreateRenderImageSource(RenderImageType.Unknown, EmbeddedResourceLoader.LoadResourceData(uri), sourceRect));
            }

            wpf::System.Windows.Media.Imaging.BitmapImage bitmapImage = new wpf::System.Windows.Media.Imaging.BitmapImage();

            bitmapImage.BeginInit();
            bitmapImage.UriSource = uri;

            if (!sourceRect.IsNullOrEmpty())
            {
                bitmapImage.SourceRect = new wpf::System.Windows.Int32Rect((int)sourceRect.Left, (int)sourceRect.Top, (int)sourceRect.Width, (int)sourceRect.Height);
            }

            bitmapImage.EndInit();

            return(new WpfRenderImageSource(bitmapImage));
        }
        public void Initialize(Uri uri, Rect sourceRect)
        {
            if (initialized)
            {
                throw new Granular.Exception("ImageSourceRenderResource is already initialized");
            }

            wpf::System.Windows.Media.Imaging.BitmapImage bitmapImage = new wpf::System.Windows.Media.Imaging.BitmapImage();
            bitmapImage.DownloadProgress  += (sender, e) => State = RenderImageState.DownloadProgress;
            bitmapImage.DownloadFailed    += (sender, e) => State = RenderImageState.DownloadFailed;
            bitmapImage.DownloadCompleted += (sender, e) =>
            {
                Size  = new Size(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
                State = RenderImageState.DownloadCompleted;
            };

            bitmapImage.BeginInit();

            if (uri.Scheme == "pack")
            {
                bitmapImage.StreamSource = new MemoryStream(EmbeddedResourceLoader.LoadResourceData(uri));
            }
            else
            {
                bitmapImage.UriSource = uri;
            }

            if (!sourceRect.IsNullOrEmpty())
            {
                bitmapImage.SourceRect = new wpf::System.Windows.Int32Rect((int)sourceRect.Left, (int)sourceRect.Top, (int)sourceRect.Width, (int)sourceRect.Height);
            }

            bitmapImage.EndInit();

            this.BitmapImage = bitmapImage;
            this.Size        = new Size(BitmapImage.PixelWidth, BitmapImage.PixelHeight);

            initialized = true;
        }
Esempio n. 5
0
        public IRenderImageSource CreateRenderImageSource(string uri, Rect sourceRect)
        {
            if (!IsUrl(uri))
            {
                return CreateRenderImageSource(RenderImageType.Unknown, EmbeddedResourceLoader.LoadResourceData(uri), sourceRect);
            }

            wpf::System.Windows.Media.Imaging.BitmapImage bitmapImage = new wpf::System.Windows.Media.Imaging.BitmapImage();

            bitmapImage.BeginInit();
            bitmapImage.UriSource = new Uri(uri);

            if (!sourceRect.IsNullOrEmpty())
            {
                bitmapImage.SourceRect = new wpf::System.Windows.Int32Rect((int)sourceRect.Left, (int)sourceRect.Top, (int)sourceRect.Width, (int)sourceRect.Height);
            }

            bitmapImage.EndInit();

            return new WpfRenderImageSource(bitmapImage);
        }
Esempio n. 6
0
        public IRenderImageSource CreateRenderImageSource(RenderImageType imageType, byte[] data, Rect sourceRect)
        {
            wpf::System.Windows.Media.Imaging.BitmapImage bitmapImage = new wpf::System.Windows.Media.Imaging.BitmapImage();

            bitmapImage.BeginInit();
            bitmapImage.StreamSource = new MemoryStream(data);

            if (!sourceRect.IsNullOrEmpty())
            {
                bitmapImage.SourceRect = new wpf::System.Windows.Int32Rect((int)sourceRect.Left, (int)sourceRect.Top, (int)sourceRect.Width, (int)sourceRect.Height);
            }

            bitmapImage.EndInit();

            return new WpfRenderImageSource(bitmapImage);
        }