コード例 #1
0
    protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
    {
        base.OnRender(drawingContext);
        var                root               = Window.GetWindow(this);
        var                adornerLayer       = AdornerLayer.GetAdornerLayer(AdornedElement);
        var                presentationSource = PresentationSource.FromVisual(adornerLayer);
        Matrix             transformToDevice  = presentationSource.CompositionTarget.TransformToDevice;
        var                sizeInPixels       = transformToDevice.Transform((Vector)adornerLayer.RenderSize);
        RenderTargetBitmap rtb           = new RenderTargetBitmap((int)(sizeInPixels.X), (int)(sizeInPixels.Y), 96, 96, PixelFormats.Default);
        var                oldEffect     = root.Effect;
        var                oldVisibility = AdornedElement.Visibility;

        root.Effect = new BlurEffect();
        AdornedElement.SetCurrentValue(FrameworkElement.VisibilityProperty, Visibility.Hidden);
        rtb.Render(root);
        AdornedElement.SetCurrentValue(FrameworkElement.VisibilityProperty, oldVisibility);
        root.Effect = oldEffect;
        drawingContext.DrawImage(rtb, adornerLayer.TransformToVisual(AdornedElement).TransformBounds(new Rect(adornerLayer.RenderSize)));
        drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(22, 0, 0, 0)), null, adornerLayer.TransformToVisual(AdornedElement).TransformBounds(new Rect(adornerLayer.RenderSize)));
        drawingContext.DrawRectangle(new VisualBrush(AdornedElement)
        {
            AlignmentX = AlignmentX.Left, TileMode = TileMode.None, Stretch = Stretch.None
        },
                                     null,
                                     AdornedElement.RenderTransform.TransformBounds(new Rect(AdornedElement.RenderSize)));
    }
コード例 #2
0
ファイル: ConvertData.cs プロジェクト: dangtq72/Chat_Lan
        public static Byte[] BitmapImage2Byte(BitmapImage imageSource)
        {
            try
            {
                //resize ve 32x32
                Rect rect = new Rect(0, 0, 32, 32);
                // Create a DrawingVisual/Context to render with
                System.Windows.Media.DrawingVisual drawingVisual = new System.Windows.Media.DrawingVisual();
                using (System.Windows.Media.DrawingContext drawingContext = drawingVisual.RenderOpen())
                {
                    drawingContext.DrawImage(imageSource, rect);
                }

                RenderTargetBitmap resizedImage = new RenderTargetBitmap(32, 32, 96, 96, System.Windows.Media.PixelFormats.Default);
                resizedImage.Render(drawingVisual);
                //
                MemoryStream     memStream = new MemoryStream();
                PngBitmapEncoder encoder   = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(resizedImage));
                encoder.Save(memStream);
                return(memStream.GetBuffer());
            }
            catch
            {
                return(new Byte[0]);
            }
        }
コード例 #3
0
        public void DrawObject(string url, string mimeType, float x, float y, float width, float height)
        {
            if (_imageLoader == null)
            {
                return;
            }

            var transform = _transform;
            var tl        = transform.Apply(x, y);
            var br        = transform.Apply(x + width, y + height);
            var screenMin = new Graphics.Point(Math.Min(tl.X, br.X), Math.Min(tl.Y, br.Y));
            var screenMax = new Graphics.Point(Math.Max(tl.X, br.X), Math.Max(tl.Y, br.Y));

            var image = _imageLoader.getImage(url, mimeType);

            if (image == null)
            {
                // image is not ready yet...
                if (_fillColor.Color.A > 0)
                {
                    var rect = new Rect(x, y, width, height);
                    PushRenderStates();
                    _drawingContext.DrawRectangle(_fillColor, null, rect);
                    PopRenderStates();
                }
            }
            else
            {
                // draw the image
                var rect = new Rect(x, y, width, height);
                PushRenderStates();
                _drawingContext.DrawImage(image, rect);
                PopRenderStates();
            }
        }
コード例 #4
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            if (ActualWidth <= 0 || ActualHeight <= 0 || Actors == null || Actors.Count() < 1)
            {
                return;
            }

            using (var bitmap = new Bitmap((int)ActualWidth, (int)ActualHeight))
            {
                using (var g = Graphics.FromImage(bitmap))
                {
                    PrepareFrame(g);

                    if (IsGridVisible)
                    {
                        DrawGrid(g);
                        DrawPoints(g);
                    }
                }

                // Copy GDI bitmap to WPF bitmap
                var hBitmap = bitmap.GetHbitmap();
                var image   = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                image.Freeze();
                dc.DrawImage(image, new Rect(RenderSize));

                DeleteObject(hBitmap);
            }
        }
コード例 #5
0
        public void DrawObject(string url, string mimeType, float x, float y, float width, float height)
        {
            if (_imageLoader == null)
            {
                return;
            }

            var transform = _transform;
            var screenMin = transform.Apply(x, y);
            var screenMax = transform.Apply(x + width, y + height);

            var image = _imageLoader.getImage(url, mimeType,
                                              (url_, image_) =>
            {
                var renderer = _imageLoader.Editor.Renderer;
                var x_       = (int)Math.Floor(screenMin.X);
                var y_       = (int)Math.Floor(screenMin.Y);
                var width_   = (int)Math.Ceiling(screenMax.X) - x_;
                var height_  = (int)Math.Ceiling(screenMax.Y) - y_;
                _target.Invalidate(renderer, x_, y_, width_, height_, LayerType.LayerType_ALL);
            });

            if (image == null)
            {
                // image is not ready yet...
                if (_fillColor.Color.A > 0)
                {
                    var rect    = new Rect(x, y, width, height);
                    var clipped = PushRenderStates();
                    _drawingContext.DrawRectangle(_fillColor, null, rect);
                    PopRenderStates(clipped);
                }
            }
            else
            {
                // adjust rectangle so that the image gets fit into original rectangle
                float fx = width / (float)image.Width;
                float fy = height / (float)image.Height;

                if (fx > fy)
                {
                    float w = (float)(image.Width * fy);
                    x    += (width - w) / 2;
                    width = w;
                }
                else
                {
                    float h = (float)(image.Height * fx);
                    y     += (height - h) / 2;
                    height = h;
                }

                // draw the image
                var rect    = new Rect(x, y, width, height);
                var clipped = PushRenderStates();
                _drawingContext.DrawImage(image, rect);
                PopRenderStates(clipped);
            }
        }
コード例 #6
0
ファイル: SharpDXElement.cs プロジェクト: loreggia/SharpDX
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (image != null && image.IsFrontBufferAvailable)
            {
                drawingContext.DrawImage(image, new Rect(new Point(), RenderSize));
            }
        }
コード例 #7
0
ファイル: ClassPrintCheck.cs プロジェクト: SokolSib/FRANCE
        private void printimage(System.Windows.Media.ImageSource bi)
        {
            var vis = new System.Windows.Media.DrawingVisual();

            System.Windows.Media.DrawingContext dc = vis.RenderOpen();
            dc.DrawImage(bi, new System.Windows.Rect {
                Width = bi.Width, Height = bi.Height
            });
            dc.Close();

            var pdialog = new System.Windows.Controls.PrintDialog();
            //  if (pdialog.ShowDialog() == true)
            {
                pdialog.PrintVisual(vis, "My Image");
            }
        }
コード例 #8
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            var component = _component;

            if (component == null)
            {
                return;
            }

            var renderTargetImage = component.RenderTargetImage;

            if (renderTargetImage != null && renderTargetImage.IsFrontBufferAvailable)
            {
                drawingContext.DrawImage(renderTargetImage, new Rect(RenderSize));
            }
        }
コード例 #9
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawRectangle(System.Windows.Media.Brushes.Black, null, new Rect(RenderSize));

            if (_initialized)
            {
                Bitmap bitmap = _buffer;

                var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                var data = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat);
                _writeableBitmap.Lock();
                Utils.CopyMemory(_writeableBitmap.BackBuffer, data.Scan0, (UInt32)(_writeableBitmap.BackBufferStride * bitmap.Height));
                _writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.Width, bitmap.Height));
                _writeableBitmap.Unlock();
                bitmap.UnlockBits(data);

                drawingContext.DrawImage(_writeableBitmap, new System.Windows.Rect(0, 0, bitmap.Width, bitmap.Height));
            }
        }
コード例 #10
0
ファイル: MapViewOld.cs プロジェクト: INSA-Projects/BedBihan
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            System.Diagnostics.Debug.WriteLine("OnRender");

            BitmapImage woodsImg = new BitmapImage();

            woodsImg.BeginInit();
            woodsImg.UriSource = new Uri("pack://application:,,,/textures/woods.png", UriKind.RelativeOrAbsolute);
            woodsImg.EndInit();
            Rect rectWoods = new Rect(0, 0, 69, 79);

            dc.DrawImage(woodsImg, rectWoods);

            /*   BitmapImage plainImg = new BitmapImage();
             * plainImg.BeginInit();
             * plainImg.UriSource = new Uri("pack://application:,,,/textures/plain.png", UriKind.RelativeOrAbsolute);
             * plainImg.EndInit();
             * Rect rectPlain = new Rect(69, 0, 69, 79);
             * dc.DrawImage(plainImg, rectPlain);
             */
        }
コード例 #11
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     drawingContext.DrawImage(_image, new Rect(RenderSize));
 }
コード例 #12
0
        public void Draw(System.Windows.Media.DrawingContext graphics)
        {
            int width  = Convert.ToInt32(System.Math.Ceiling(board.PixelWidth));
            int height = Convert.ToInt32(System.Math.Ceiling(board.PixelHeight));

            // seems to be needed to avoid bottom and right from being chopped off
            width  += 1;
            height += 1;

            //
            // Create drawing objects
            //
            Bitmap     bitmap         = new Bitmap(width, height);
            Graphics   bitmapGraphics = Graphics.FromImage(bitmap);
            Pen        p  = new Pen(Color.Black);
            SolidBrush sb = new SolidBrush(Color.Black);


            //
            // Draw Board background
            //
            sb = new SolidBrush(board.BoardState.BackgroundColor);
            bitmapGraphics.FillRectangle(sb, 0, 0, width, height);

            //
            // Draw Hex Background
            //
            for (int i = 0; i < board.Hexes.GetLength(0); i++)
            {
                for (int j = 0; j < board.Hexes.GetLength(1); j++)
                {
                    //bitmapGraphics.DrawPolygon(p, board.Hexes[i, j].Points);
                    if (board.Hexes[i, j] != null)
                    {
                        bitmapGraphics.FillPolygon(new SolidBrush(board.Hexes[i, j].HexState.BackgroundColor),
                                                   board.Hexes[i, j].Points);
                    }
                }
            }


            //
            // Draw Hex Grid
            //
            p.Color = board.BoardState.GridColor;
            p.Width = board.BoardState.GridPenWidth;

            for (int i = 0; i < board.Hexes.GetLength(0); i++)
            {
                for (int j = 0; j < board.Hexes.GetLength(1); j++)
                {
                    if (board.Hexes[i, j] != null)
                    {
                        p.Color = board.Hexes[i, j].HexState.BorderColor;
                        bitmapGraphics.DrawPolygon(p, board.Hexes[i, j].Points);
                        if (board.MapData != null)
                        {
                            Hex hex = board.Hexes[i, j];
                            if (hex.Row >= 0 && hex.Row < board.MapData.width && hex.Col >= 0 && hex.Col < board.MapData.height)
                            {
                                DrawText(bitmapGraphics, board.Hexes[i, j], board.Hexes[i, j].Points);
                            }
                        }
                    }
                }
            }

            //
            // Draw Active Hex, if present
            //
            if (board.BoardState.ActiveHex != null)
            {
                p.Color = board.BoardState.ActiveHexBorderColor;
                p.Width = board.BoardState.ActiveHexBorderWidth;
                bitmapGraphics.DrawPolygon(p, board.BoardState.ActiveHex.Points);
            }

            //
            // Draw internal bitmap to screen
            //


            graphics.DrawImage(ToBitmapImage2(bitmap),
                               new System.Windows.Rect(0, 0, bitmap.Width, bitmap.Height));
            //graphics.DrawImage(bitmap, new Point(this.boardXOffset , this.boardYOffset));

            //
            // Release objects
            //
            bitmapGraphics.Dispose();
            bitmap.Dispose();
        }
コード例 #13
0
ファイル: Adorners.cs プロジェクト: jorik041/AppsTracker
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     drawingContext.DrawImage(new BitmapImage(new Uri(@"pack://application:,,,/Resources/down.png")), new Rect(0, 0, width, height));
     base.OnRender(drawingContext);
 }