コード例 #1
0
ファイル: LineCapComboBox.xaml.cs プロジェクト: olesar/Altaxo
        public static ImageSource GetImage(LineCapExtension join, bool isForEndCap)
        {
            const int    bmpHeight = 24;
            const int    bmpWidth  = 48;
            const double lineWidth = bmpHeight * 0.4;

            if (null == _interopBitmap)
            {
                _interopBitmap = new GdiToWpfBitmap(bmpWidth, bmpHeight);
            }

            using (var grfx = _interopBitmap.BeginGdiPainting())
            {
                grfx.CompositingMode = sdd.CompositingMode.SourceCopy;
                grfx.FillRectangle(System.Drawing.Brushes.Transparent, 0, 0, bmpWidth, bmpHeight);

                var linePen = new System.Drawing.Pen(System.Drawing.Brushes.Black, (float)Math.Ceiling(lineWidth));
                if (isForEndCap)
                {
                    join.SetEndCap(linePen);
                    grfx.DrawLine(linePen, 0, 0.5f * bmpHeight, bmpWidth * (1 - 0.25f), 0.5f * bmpHeight);
                }
                else
                {
                    join.SetStartCap(linePen);
                    grfx.DrawLine(linePen, 0.25f * bmpWidth, 0.5f * bmpHeight, bmpWidth, 0.5f * bmpHeight);
                }
                _interopBitmap.EndGdiPainting();
            }

            var img = new WriteableBitmap(_interopBitmap.WpfBitmap);

            img.Freeze();
            return(img);
        }
コード例 #2
0
        /// <summary>
        /// Called by the PresentationGraphController to get a new graphics context for painting.
        /// </summary>
        /// <returns></returns>
        public static System.Drawing.Graphics GetGraphicsContextFromWpfGdiBitmap(GdiToWpfBitmap gdiWpfBitmap)
        {
            var grfx = gdiWpfBitmap.BeginGdiPainting();

            grfx.ResetTransform();
            grfx.PageScale = 1;
            grfx.PageUnit  = System.Drawing.GraphicsUnit.Pixel;
            return(grfx);
        }
コード例 #3
0
 public void InvalidatePreviewPanel()
 {
     if (_controller != null)
     {
         using (var grfx = _previewBitmap.BeginGdiPainting())
         {
             _controller.EhView_PreviewPanelPaint(grfx);
             _previewBitmap.EndGdiPainting();
         }
     }
 }
コード例 #4
0
        public void UpdatePreview(BrushX brush)
        {
            if (null == _previewPanel || null == brush)
            {
                return;
            }

            int height = (int)_previewPanel.ActualHeight;
            int width  = (int)_previewPanel.ActualWidth;

            if (height <= 0)
            {
                height = 64;
            }
            if (width <= 0)
            {
                width = 64;
            }

            if (null == _previewBitmap)
            {
                _previewBitmap       = new GdiToWpfBitmap(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            if (width != _previewBitmap.GdiRectangle.Width || height != _previewBitmap.GdiRectangle.Height)
            {
                _previewBitmap.Resize(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            using (var grfx = _previewBitmap.BeginGdiPainting())
            {
                var fullRect = _previewBitmap.GdiRectangle;

                grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                grfx.FillRectangle(System.Drawing.Brushes.Transparent, fullRect);
                grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                var r2 = fullRect;
                r2.Inflate(-r2.Width / 4, -r2.Height / 4);
                //grfx.FillRectangle(System.Drawing.Brushes.Black, r2);

                brush.SetEnvironment(fullRect, BrushX.GetEffectiveMaximumResolution(grfx));
                grfx.FillRectangle(brush, fullRect);

                _previewBitmap.EndGdiPainting();
            }
        }
コード例 #5
0
        private void UpdatePreview()
        {
            if (null == _previewBitmap || null == _previewData || _previewData.Length == 0)
            {
                return;
            }

            // original sizes
            double ow = _previewData[0].PhysicalSize.Width;
            double oh = _previewData[0].PhysicalSize.Height;

            // destination sizes and locations
            double dl = Math.Min(4, _previewBitmap.GdiRectangle.Width / 8.0);  // left
            double dt = Math.Min(4, _previewBitmap.GdiRectangle.Height / 8.0); // top
            double dw = _previewBitmap.GdiRectangle.Width - 2 * dl;            // width
            double dh = _previewBitmap.GdiRectangle.Height - 2 * dt;           // height

            System.Drawing.Rectangle destRect;

            if (oh / ow > dh / dw) // if the original image is more portrait than the destination rectangle
            {
                // use the full height, but restrict the destination with
                var rw = dh * ow / oh;
                destRect = new System.Drawing.Rectangle((int)(0.5 * (dw - rw) + dl), (int)dt, (int)rw, (int)dh);
            }
            else // if the original image is more landscape than the destination rectangle
            {
                var rh = dw * oh / ow;
                destRect = new System.Drawing.Rectangle((int)dl, (int)(0.5 * (dh - rh) + dt), (int)dw, (int)rh);
            }

            using (var grfx = _previewBitmap.BeginGdiPainting())
            {
                grfx.FillRectangle(System.Drawing.Brushes.White, _previewBitmap.GdiRectangle);
                grfx.DrawRectangle(System.Drawing.Pens.Black, destRect);

                _previewPageNumber = Math.Max(0, Math.Min(_previewPageNumber, _previewData.Length - 1));
                grfx.DrawImage(_previewData[_previewPageNumber].Image, destRect);
                _previewBitmap.EndGdiPainting();
            }
        }
コード例 #6
0
        private void UpdatePreviewPanel()
        {
            if (null == _previewPanel || null == _pen)
            {
                return;
            }

            int height = (int)_previewPanel.ActualHeight;
            int width  = (int)_previewPanel.ActualWidth;

            if (height <= 0)
            {
                height = 64;
            }
            if (width <= 0)
            {
                width = 64;
            }

            if (null == _previewBitmap)
            {
                _previewBitmap       = new GdiToWpfBitmap(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            if (width != _previewBitmap.GdiRectangle.Width || height != _previewBitmap.GdiRectangle.Height)
            {
                _previewBitmap.Resize(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            using (var grfx = _previewBitmap.BeginGdiPainting())
            {
                var fullRect = _previewBitmap.GdiRectangle;
                grfx.FillRectangle(System.Drawing.Brushes.White, fullRect);
                _pen.BrushHolder.SetEnvironment(fullRect, BrushX.GetEffectiveMaximumResolution(grfx));
                grfx.DrawLine(_pen, fullRect.Width / 6, fullRect.Height / 2, (fullRect.Width * 5) / 6, fullRect.Height / 2);

                _previewBitmap.EndGdiPainting();
            }
        }
コード例 #7
0
ファイル: GraphViewWpf.xaml.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Called by the PresentationGraphController to get a new graphics context for painting.
		/// </summary>
		/// <returns></returns>
		public static System.Drawing.Graphics GetGraphicsContextFromWpfGdiBitmap(GdiToWpfBitmap gdiWpfBitmap)
		{
			var grfx = gdiWpfBitmap.BeginGdiPainting();
			grfx.ResetTransform();
			grfx.PageScale = 1;
			grfx.PageUnit = System.Drawing.GraphicsUnit.Pixel;
			return grfx;
		}