public static Brush CreateImageParticle(Color color, Uri source, int renderSize)
        {
            BitmapImage bi = new BitmapImage();

            bi.BeginInit();
            bi.UriSource = source;
            bi.EndInit();

            AlphaMaskEffect effect = new AlphaMaskEffect();

            effect.Color = color;

            RenderTargetBitmap rtb = PrepareRenderTarget(renderSize);

            System.Windows.Shapes.Rectangle visual = new System.Windows.Shapes.Rectangle();
            visual.Fill   = new ImageBrush(bi);
            visual.Effect = effect;

            Size sz = new Size(renderSize, renderSize);

            visual.Measure(sz);
            visual.Arrange(new Rect(sz));

            rtb.Render(visual);

            return(new ImageBrush(rtb));
        }
Exemplo n.º 2
0
        /// <summary>Creates the screenshot of entire plotter element</summary>
        /// <returns></returns>
        internal static BitmapSource CreateScreenshot(UIElement uiElement, Int32Rect screenshotSource)
        {
            Window window = Window.GetWindow(uiElement);
            if (window == null)
            {
                return CreateElementScreenshot(uiElement);
            }
            Size size = window.RenderSize;

            //double dpiCoeff = 32 / SystemParameters.CursorWidth;
            //int dpi = (int)(dpiCoeff * 96);
            double dpiCoeff = 1;
            int dpi = 96;

            RenderTargetBitmap bmp = new RenderTargetBitmap(
                (int)(size.Width * dpiCoeff), (int)(size.Height * dpiCoeff),
                dpi, dpi, PixelFormats.Default);

			// white background
			Rectangle whiteRect = new Rectangle { Width = size.Width, Height = size.Height, Fill = Brushes.White };
			whiteRect.Measure(size);
			whiteRect.Arrange(new Rect(size));
			bmp.Render(whiteRect);
			// the very element
            bmp.Render(uiElement);

            CroppedBitmap croppedBmp = new CroppedBitmap(bmp, screenshotSource);
            return croppedBmp;
        }
        public static Brush CreateBaseImageParticle(Color color)
        {
            BitmapImage bi = new BitmapImage();

            bi.BeginInit();
            bi.UriSource = new Uri("pack://application:,,,/resources/images/particles/base-particle.png");
            bi.EndInit();

            ColorReplaceEffect effect = new ColorReplaceEffect();

            effect.ColorToOverride = Colors.White;
            effect.ColorReplace    = color;

            RenderTargetBitmap rtb = PrepareRenderTarget(128);

            System.Windows.Shapes.Rectangle visual = new System.Windows.Shapes.Rectangle();
            visual.Fill   = new ImageBrush(bi);
            visual.Effect = effect;

            Size sz = new Size(128, 128);

            visual.Measure(sz);
            visual.Arrange(new Rect(sz));

            rtb.Render(visual);

            return(new ImageBrush(rtb));
        }
Exemplo n.º 4
0
        private void SaveToFile(Viewport3D v, int width, int height)
        {
            if (Directory.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData") == false)
            { Directory.CreateDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData"); }

            string destination = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + " " +
                DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + " " + Environment.UserName + " 3dView.png";

            Rectangle vRect = new Rectangle { Width = width, Height = height, Fill = Brushes.White };
            vRect.Arrange(new Rect(0, 0, vRect.Width, vRect.Height));

            var bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(vRect);
            bmp.Render(v);

            var png = new PngBitmapEncoder();
            png.Frames.Add(BitmapFrame.Create(bmp));

            using (var stm = File.Create(destination)) { png.Save(stm); }
        }
Exemplo n.º 5
0
        static void Apply(Shader shader, BitmapImage bitmap, string destImage)
        {
            Rectangle r = new Rectangle ();
            r.Effect = shader;
            shader.Input = new ImageBrush (bitmap);
            /*The fill brush is ignored due to the effect been applied*/
            r.Fill = new SolidColorBrush (Colors.Aquamarine);

            Size size = new Size (bitmap.PixelWidth, bitmap.PixelHeight);
            r.Measure (size);
            r.Arrange (new Rect (size));

            RenderTargetBitmap render = new RenderTargetBitmap (
                bitmap.PixelWidth,
                bitmap.PixelHeight,
                96,
                96,
                PixelFormats.Pbgra32);

            render.Render (r);

            PngBitmapEncoder png = new PngBitmapEncoder ();
            png.Frames.Add (BitmapFrame.Create (render));
            using (Stream stm = File.Open (destImage, FileMode.OpenOrCreate)) {
                png.Save (stm);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Renders the viewport to a bitmap.
        /// </summary>
        /// <param name="view">The viewport.</param>
        /// <param name="background">The background.</param>
        /// <param name="m">The oversampling multiplier.</param>
        /// <returns>A bitmap.</returns>
        public static BitmapSource RenderBitmap(this Viewport3DX view, Brush background, int m = 1)
        {
            var target = new WriteableBitmap(
                (int)view.ActualWidth * m, (int)view.ActualHeight * m, 96, 96, PixelFormats.Pbgra32, null);

            var originalCamera = view.Camera;
            var vm = originalCamera.GetViewMatrix3D();
            double ar = view.ActualWidth / view.ActualHeight;

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    // change the camera viewport and scaling
                    var pm = originalCamera.GetProjectionMatrix3D(ar);
                    if (originalCamera is OrthographicCamera)
                    {
                        pm.OffsetX = m - 1 - (i * 2);
                        pm.OffsetY = -(m - 1 - (j * 2));
                    }

                    if (originalCamera is PerspectiveCamera)
                    {
                        pm.M31 = -(m - 1 - (i * 2));
                        pm.M32 = m - 1 - (j * 2);
                    }

                    pm.M11 *= m;
                    pm.M22 *= m;

                    var mc = new MatrixCamera(vm, pm);
                    view.Camera = mc;

                    var partialBitmap = new RenderTargetBitmap(
                        (int)view.ActualWidth, (int)view.ActualHeight, 96, 96, PixelFormats.Pbgra32);

                    // render background
                    var backgroundRectangle = new Rectangle
                        {
                            Width = partialBitmap.Width,
                            Height = partialBitmap.Height,
                            Fill = background
                        };
                    backgroundRectangle.Arrange(new Rect(0, 0, backgroundRectangle.Width, backgroundRectangle.Height));
                    partialBitmap.Render(backgroundRectangle);

                    // render 3d
                    partialBitmap.Render(view);

                    // copy to the target bitmap
                    CopyBitmap(partialBitmap, target, (int)(i * view.ActualWidth), (int)(j * view.ActualHeight));
                }
            }

            // restore the camera
            view.Camera = originalCamera;
            return target;
        }
        protected override void CreateHeatMap()
        {
            intensityMap = new RenderTargetBitmap(500, 500, 96, 96, PixelFormats.Pbgra32);
            AddativeBlendClear cleareffect = new AddativeBlendClear();
            cleareffect.ClearColor = Color.FromArgb(0x01, 0xFF, 0xFF, 0xFF);

            ClearIntensityMap();
            Size sz = new Size(intensityMap.PixelWidth, intensityMap.PixelHeight);

            // Create the clear rectangle, we need this to render a fade pass.
            clearRectangle = new Rectangle();
            clearRectangle.Fill = new ImageBrush(intensityMap);
            clearRectangle.Effect = cleareffect;
            clearRectangle.Measure(sz);
            clearRectangle.Arrange(new Rect(sz));

            // Connect the intensity map containing our heat to our image.
            HeatMapImage.Source = intensityMap;
        }
        // CreateScreenShot should handle the situation when the FlowDirection of Designer's 
        // parent is RightToLeft
        // 
        // The structure:
        // Root
        //   |--DesignerView
        // The DesignerView is what we're trying to capture.
        // 
        // If Root.FlowDirection is RightToLeft, the DesignerView's capture is a flipped image.
        // Say, if DesignerView is diplayed on screen:
        // -->==>
        // the captured image would be:
        // <==<--
        // It is Root who flips the image before diplaying on screen.
        // But, in our capture, Root will not do the flipping work for us, so we flip the image
        // before return.
        BitmapSource CreateScreenShot()
        {
            const double DPI = 96.0;

            Rect bounds = VisualTreeHelper.GetDescendantBounds(this.designerPresenter);
            int imageWidth = (int)Math.Ceiling(bounds.Right);
            int imageHeight = (int)Math.Ceiling(bounds.Bottom);
            Rectangle background = new Rectangle()
            {
                // WindowBrush:
                //  Gets a SolidColorBrush that is the background 
                //  color in the client area of a window.  
                Fill = new SolidColorBrush(WorkflowDesignerColors.DesignerViewBackgroundColor),
                Width = imageWidth,
                Height = imageHeight,
            };

            background.Arrange(new Rect(0, 0, imageWidth, imageHeight));

            RenderTargetBitmap renderBitmap = new RenderTargetBitmap(imageWidth, imageHeight, DPI, DPI, PixelFormats.Pbgra32);
            renderBitmap.Render(background);
            renderBitmap.Render(this.designerPresenter);

            BitmapSource source = BitmapFrame.Create(renderBitmap);

            if (IsRightToLeft(this.designerPresenter))
            {
                return new TransformedBitmap(source, new ScaleTransform(-1, 1, imageWidth / 2, 0));
            }

            return source;
        }
Exemplo n.º 9
0
        private static BitmapSource CreateElementScreenshot(UIElement uiElement)
        {
            bool measureValid = uiElement.IsMeasureValid;

            if (!measureValid)
            {
                double width = 300;
                double height = 300;

                FrameworkElement frElement = uiElement as FrameworkElement;
                if (frElement != null)
                {
                    if (!Double.IsNaN(frElement.Width))
                        width = frElement.Width;
                    if (!Double.IsNaN(frElement.Height))
                        height = frElement.Height;
                }

                Size size = new Size(width, height);
                uiElement.Measure(size);
                uiElement.Arrange(new Rect(size));
            }

            RenderTargetBitmap bmp = new RenderTargetBitmap(
                (int)uiElement.RenderSize.Width, (int)uiElement.RenderSize.Height,
                96, 96, PixelFormats.Default);

            // this is waiting for dispatcher to perform measure, arrange and render passes
            uiElement.Dispatcher.Invoke(((Action)(() => { })), DispatcherPriority.Background);

			Size elementSize = uiElement.DesiredSize;
			// white background
			Rectangle whiteRect = new Rectangle { Width = elementSize.Width, Height = elementSize.Height, Fill = Brushes.White };
			whiteRect.Measure(elementSize);
			whiteRect.Arrange(new Rect(elementSize));
			bmp.Render(whiteRect);

            bmp.Render(uiElement);

            return bmp;
        }
        private Stream LoadImage(string srcFileName)
        {
            imgSrc = srcFileName;

            imageSource = new BitmapImage(new Uri(srcFileName,UriKind.RelativeOrAbsolute));
            columns = (int)Math.Ceiling(imageSource.PixelWidth / 100.0);
            rows = (int)Math.Ceiling(imageSource.PixelHeight / 100.0);

            var bi = new BitmapImage(new Uri(srcFileName,UriKind.RelativeOrAbsolute));
            var imgBrush = new ImageBrush(bi);
            imgBrush.AlignmentX = AlignmentX.Left;
            imgBrush.AlignmentY = AlignmentY.Top;
            imgBrush.Stretch = Stretch.UniformToFill;

            RenderTargetBitmap rtb = new RenderTargetBitmap((columns + 1) * 100, (rows + 1) * 100, bi.DpiX, bi.DpiY, PixelFormats.Pbgra32);

            var rectBlank = new System.Windows.Shapes.Rectangle();
            rectBlank.Width = columns * 100;
            rectBlank.Height = rows * 100;
            rectBlank.HorizontalAlignment = HorizontalAlignment.Left;
            rectBlank.VerticalAlignment = VerticalAlignment.Top;
            rectBlank.Fill = new SolidColorBrush(Colors.White);
            rectBlank.Arrange(new Rect(0, 0, columns * 100, rows * 100));

            var rectImage = new System.Windows.Shapes.Rectangle();
            rectImage.Width = imageSource.PixelWidth;
            rectImage.Height = imageSource.PixelHeight;
            rectImage.HorizontalAlignment = HorizontalAlignment.Left;
            rectImage.VerticalAlignment = VerticalAlignment.Top;
            rectImage.Fill = imgBrush;
            rectImage.Arrange(new Rect((columns * 100 - imageSource.PixelWidth) / 2, (rows * 100 - imageSource.PixelHeight) / 2, imageSource.PixelWidth, imageSource.PixelHeight));

            rectImage.Margin = new Thickness(
                (columns * 100 - imageSource.PixelWidth) / 2,
                (rows * 100 - imageSource.PixelHeight) / 2,
                (rows * 100 - imageSource.PixelHeight) / 2,
                (columns * 100 - imageSource.PixelWidth) / 2);

            rtb.Render(rectBlank);
            rtb.Render(rectImage);

            png = new PngBitmapEncoder();
            png.Frames.Add(BitmapFrame.Create(rtb));

            Stream ret = new MemoryStream();

            png.Save(ret);

            return ret;
        }
Exemplo n.º 11
0
 public SquaredArrow()
 {
     Rectangle r = new Rectangle();
     r.Measure(new Size(100, 100));
     r.Arrange(new Rect(0, 0, 100, 100));
 }
Exemplo n.º 12
0
        //Load image stream
        private Stream LoadImage(string srcFileName)
        {
            this._columns = (int)Math.Ceiling((double)(((double)this.SupportedImageHeight) / this.PieceSize));
            this._rows = (int)Math.Ceiling((double)(((double)this.SupportedImageHeight) / this.PieceSize));
            var bi = new BitmapImage(new Uri(srcFileName));

            var imgBrush = new ImageBrush(bi)
            {
                AlignmentX = AlignmentX.Left,
                AlignmentY = AlignmentY.Top,
                Stretch = Stretch.UniformToFill
            };

            var rectBlank = new Rectangle
            {
                Width = this._columns * this.PieceSize,
                Height = this._rows * this.PieceSize,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Fill = new SolidColorBrush(Colors.White)
            };
            rectBlank.Arrange(new Rect(0.0, 0.0, this._columns * this.PieceSize, this._rows * this.PieceSize));
            var rectImage = new Rectangle
            {
                Width = this.SupportedImageWidth,
                Height = this.SupportedImageHeight,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Fill = imgBrush
            };
            rectImage.Arrange(new Rect(((this._columns * this.PieceSize) - this.SupportedImageWidth) / 2.0,
                                       ((this._rows * this.PieceSize) - this.SupportedImageHeight) / 2.0,
                                       (double)this.SupportedImageWidth, (double)this.SupportedImageHeight));
            rectImage.Margin = new Thickness(((this._columns * this.PieceSize) - this.SupportedImageWidth) / 2.0,
                                             ((this._rows * this.PieceSize) - this.SupportedImageHeight) / 2.0,
                                             ((this._rows * this.PieceSize) - this.SupportedImageHeight) / 2.0,
                                             ((this._columns * this.PieceSize) - this.SupportedImageWidth) / 2.0);
            var rtb = new RenderTargetBitmap((this._columns + 1) * ((int)this.PieceSize),
                                                            (this._rows + 1) * ((int)this.PieceSize), bi.DpiX, bi.DpiY,
                                                            PixelFormats.Pbgra32);
            rtb.Render(rectBlank);
            rtb.Render(rectImage);
            var png = new PngBitmapEncoder
            {
                Frames = { BitmapFrame.Create(rtb) }
            };
            Stream ret = new MemoryStream();
            png.Save(ret);
            return ret;
        }