예제 #1
0
        /// <see cref="IDiagramRenderer.Render(Diagram)"/>
        public ImageSource Render(Diagram diagram)
        {
            Uri imageUri;

            if (diagram.ImageFile == null || !diagram.ImageFile.Exists ||
                !Uri.TryCreate(diagram.ImageFile.FullName, UriKind.RelativeOrAbsolute, out imageUri))
            {
                return(null);
            }

            var bitmap = new BitmapImage();

            using (bitmap.BeginInitialize())
            {
                bitmap.UriSource = imageUri;

                // OMAR: Trick #6
                // Unless we use this option, the image file is locked and cannot be modified.
                // Looks like WPF holds read lock on the images. Very bad.
                bitmap.CacheOption = BitmapCacheOption.OnLoad;

                // Unless we use this option, an image cannot be refreshed. It loads from
                // cache. Looks like WPF caches every image it loads in memory. Very bad.
                bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
            }

            return(bitmap);
        }
예제 #2
0
        /// <see cref="IDiagramRenderer.Render(Stream)"/>
        public ImageSource Render(Stream imageData)
        {
            var bitmap = new BitmapImage();

            using (bitmap.BeginInitialize())
                bitmap.StreamSource = imageData;

            bitmap.Freeze();
            return(bitmap);
        }