Beispiel #1
0
        /// <summary>
        /// 计算图像直方图
        /// </summary>
        /// <param name="ChartWidth">图的宽度</param>
        /// <param name="ChartHeight">图的高度</param>
        private void GetHistogram(int ChartWidth, int ChartHeight)
        {
            int[]  red         = new int[256];
            int[]  green       = new int[256];
            int[]  blue        = new int[256];
            double WidthOffset = (double)ChartWidth / 256;
            string reds        = "M 0," + ChartHeight + " ";
            string greens      = "M 0," + ChartHeight + " ";
            string blues       = "M 0," + ChartHeight + " ";

            core.PicProcess picProcess = new core.PicProcess();
            int             max        = picProcess.GetPixelCount(pic, red, green, blue);

            for (int i = 0; i < 256; i++)
            {
                int y = ChartHeight - ChartHeight * red[i] / max;
                reds   += (i * WidthOffset).ToString() + "," + y.ToString() + " ";
                y       = ChartHeight - ChartHeight * green[i] / max;
                greens += (i * WidthOffset).ToString() + "," + y.ToString() + " ";
                y       = ChartHeight - ChartHeight * blue[i] / max;
                blues  += (i * WidthOffset).ToString() + "," + y.ToString() + " ";
            }
            reds   += ChartWidth + "," + ChartHeight + " Z";
            greens += ChartWidth + "," + ChartHeight + " Z";
            blues  += ChartWidth + "," + ChartHeight + " Z";
            var converter = TypeDescriptor.GetConverter(typeof(System.Windows.Media.Geometry));

            RedPath   = (System.Windows.Media.Geometry)converter.ConvertFrom(reds);
            GreenPath = (System.Windows.Media.Geometry)converter.ConvertFrom(greens);
            BluePath  = (System.Windows.Media.Geometry)converter.ConvertFrom(blues);
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("RedPath"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GreenPath"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BluePath"));
        }
Beispiel #2
0
 protected Task <PolyBezierLayer> GetBezier(System.Windows.Media.Geometry symbol, VisualParameters decorationVisual)
 {
     if (RequestGetBezier != null)
     {
         return(RequestGetBezier(symbol, decorationVisual));
     }
     else
     {
         return(new Task <PolyBezierLayer>(null));
     }
 }
Beispiel #3
0
 public System.Windows.Media.Geometry get_clip(double nx, double ny)
 {
     System.Windows.Media.Geometry v = null;
     if (vp is eq.gui.vg.VgPathRectangle)
     {
         double aw = vp.get_w(), ah = vp.get_h();
         if (aw > 0 && ah > 0)
         {
             var rect = new System.Windows.Media.RectangleGeometry();
             rect.Rect = new System.Windows.Rect(x + vp.get_x() - nx, y + vp.get_y() - ny, aw, ah);
             v         = rect;
         }
     }
     else if (vp is eq.gui.vg.VgPathRoundedRectangle)
     {
         var    vpr = vp as eq.gui.vg.VgPathRoundedRectangle;
         double aw = vpr.get_w(), ah = vpr.get_h(), rd = vpr.get_radius();
         if (aw > 0 && ah > 0 && rd > 0)
         {
             var rrect = new System.Windows.Media.RectangleGeometry();
             rrect.Rect    = new System.Windows.Rect(x + vp.get_x() - nx, y + vp.get_y() - ny, aw, ah);
             rrect.RadiusX = rd;
             rrect.RadiusY = rd;
             v             = rrect;
         }
     }
     else if (vp is eq.gui.vg.VgPathCircle)
     {
         var    vpc = vp as eq.gui.vg.VgPathCircle;
         double rd  = vpc.get_radius();
         if (rd > 0)
         {
             var circle = new System.Windows.Media.EllipseGeometry();
             circle.Center  = new System.Windows.Point(x + vpc.get_xc() - nx, y + vpc.get_yc() - ny);
             circle.RadiusX = rd;
             circle.RadiusY = rd;
             v = circle;
         }
     }
     else if (vp is eq.gui.vg.VgPathCustom)
     {
         var cp     = vp as eq.gui.vg.VgPathCustom;
         var itr    = cp.iterate();
         var pg     = new System.Windows.Media.PathGeometry();
         var figure = new System.Windows.Media.PathFigure()
         {
             StartPoint = new System.Windows.Point(x + cp.get_start_x() - nx, y + cp.get_start_y() - ny)
         };
         while (itr != null)
         {
             var vpe = itr.next() as eq.gui.vg.VgPathElement;
             if (vpe == null)
             {
                 break;
             }
             System.Windows.Media.PathSegment segment = null;
             if (vpe.get_operation() == eq.gui.vg.VgPathElement.OP_LINE)
             {
                 segment = new System.Windows.Media.LineSegment()
                 {
                     Point = new System.Windows.Point(x + vpe.get_x1() - nx, y + vpe.get_y1() - ny)
                 };
             }
             else if (vpe.get_operation() == eq.gui.vg.VgPathElement.OP_CURVE)
             {
                 segment = new System.Windows.Media.BezierSegment()
                 {
                     Point1 = new System.Windows.Point(x + vpe.get_x1() - nx, y + vpe.get_y1() - ny),
                     Point2 = new System.Windows.Point(x + vpe.get_x2() - nx, y + vpe.get_y2() - ny),
                     Point3 = new System.Windows.Point(x + vpe.get_x3() - ny, y + vpe.get_y3() - ny)
                 };
             }
             else if (vpe.get_operation() == eq.gui.vg.VgPathElement.OP_ARC)
             {
             }
             else
             {
                 eq.api.Log.eq_api_Log_error((eq.api.Object)eq.api.StringStatic.eq_api_StringStatic_for_strptr("Unknown path element encountered."), null, null);
             }
             if (segment != null)
             {
                 figure.Segments.Add(segment);
             }
         }
         pg.Figures.Add(figure);
         v = pg;
     }
     if (vt != null)
     {
         double scx = vt.get_scale_x(), scy = vt.get_scale_y();
         double rot = vt.get_rotate_angle();
         var    tg  = new System.Windows.Media.TransformGroup();
         if (scx != 1.0 || scy != 1.0)
         {
             var st = new System.Windows.Media.ScaleTransform()
             {
                 ScaleX = scx, ScaleY = scy
             };
             st.CenterX = v.Bounds.Width / 2;
             st.CenterY = v.Bounds.Height / 2;
             tg.Children.Add(st);
         }
         if (rot != 0.0)
         {
             var rt = new System.Windows.Media.RotateTransform()
             {
                 Angle = rot
             };
             rt.CenterX = v.Bounds.Width / 2;
             rt.CenterY = v.Bounds.Height / 2;
             tg.Children.Add(rt);
         }
         if (vt.get_flip_horizontal())
         {
             var fht = new System.Windows.Media.ScaleTransform()
             {
                 ScaleX = -1.0, ScaleY = scy
             };
             fht.CenterX = v.Bounds.Width / 2;
             tg.Children.Add(fht);
         }
         v.Transform = tg;
     }
     return(v);
 }
 private static WpfGeometry CreateGeometry(params string[] geometryStrings)
 {
     return(WpfGeometry.Parse(string.Join(" ", geometryStrings)));
 }
Beispiel #5
0
 public static void SetData(System.Windows.DependencyObject obj, System.Windows.Media.Geometry value)
 {
     obj.SetValue(DataProperty, value);
 }
Beispiel #6
0
        public Image CreateImage()
        {
            using (Bitmap desktop = CaptureScreen.CaptureScreen.GetDesktopImage())
            {
                System.Windows.Media.Geometry shapeGeometry = GetCaptureShape();
                System.Windows.Rect           bounds        =
                    shapeGeometry.GetRenderBounds(new System.Windows.Media.Pen(System.Windows.Media.Brushes.Black, 1));

                System.Windows.Point screenTopLeft  = _surface.PointToScreen(bounds.TopLeft),
                                     screenBotRight = _surface.PointToScreen(bounds.BottomRight);


                RectangleF screenRect =
                    new RectangleF((float)screenTopLeft.X, (float)screenTopLeft.Y,
                                   (float)(screenBotRight.X - screenTopLeft.X),
                                   (float)(screenBotRight.Y - screenTopLeft.Y)),

                           dstRect = new RectangleF(0, 0, screenRect.Width, screenRect.Height);

                System.Drawing.Bitmap img = new Bitmap((int)dstRect.Width, (int)dstRect.Height);
                img.SetResolution(desktop.HorizontalResolution, desktop.VerticalResolution);
                using (Graphics g = Graphics.FromImage(img))
                {
                    g.Clear(Color.Transparent);
                    g.DrawImage(desktop, dstRect, screenRect, GraphicsUnit.Pixel);
                }

                System.Drawing.Imaging.BitmapData data = null;
                try
                {
                    data = img.LockBits(
                        new Rectangle(0, 0, (int)dstRect.Width, (int)dstRect.Height),
                        System.Drawing.Imaging.ImageLockMode.ReadWrite,
                        img.PixelFormat);

                    // Get the address of the first line.
                    IntPtr ptr = data.Scan0;
                    // Assume 4 channels - blue, green, red, alpha
                    int bytesPerPixel = 4;
                    // Declare an array to hold the bytes of the bitmap.
                    // This code is specific to a bitmap with 32 bits per pixels
                    // (32 bits = 4 bytes, 3 for RGB and 1 byte for alpha).
                    int    numBytes   = img.Width * img.Height * bytesPerPixel;
                    byte[] argbValues = new byte[numBytes];

                    // Copy the ARGB values into the array.
                    System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, numBytes);

                    int stride = data.Stride,
                        bytes  = data.Stride * img.Height;

                    // Split the points into x and y vertices
                    System.Collections.ObjectModel.ReadOnlyCollection <System.Drawing.Point> points = _shape.Points;
                    List <float> vx = new List <float>(), vy = new List <float>();
                    foreach (System.Drawing.Point p in points)
                    {
                        vx.Add(p.X);
                        vy.Add(p.Y);
                    }

                    // Set alpha channel to 0 for all pixels not within the selected shape.
                    // This is the slowest part of the capture.
                    ScreenInfo si = ScreenInfo.AllScreenInfo;
                    for (int y = 0; y < data.Height; y++)
                    {
                        for (int x = 0; x < data.Width; x++)
                        {
                            // Offset by the lowest screen points
                            System.Windows.Point scr = new System.Windows.Point((float)(x + screenTopLeft.X - si.MinX),
                                                                                (float)(y + screenTopLeft.Y - si.MinY));
                            bool poly = pnpoly(points.Count, vx, vy, (float)scr.X, (float)scr.Y);
                            if (!poly)
                            {
                                argbValues[(y * stride) + (x * bytesPerPixel) + 3] = 0;
                            }
                        }
                    }

                    // Copy the ARGB values back to the bitmap
                    System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, ptr, numBytes);
                }
                finally
                {
                    if (data != null)
                    {
                        img.UnlockBits(data);
                    }
                }

                return(img);
                //System.Windows.Media.Imaging.PngBitmapEncoder encoder =
                //    new System.Windows.Media.Imaging.PngBitmapEncoder();
            }
        }
Beispiel #7
0
 public void AddPolyBezierLayer(string name, List <Ham.SpatialBase.Point> bezierPoints, System.Windows.Media.Geometry symbol, VisualParameters decorationVisuals, bool showSymbolOnly)
 {
     this.RequestAddPolyBezier?.Invoke(name, bezierPoints, symbol, showSymbolOnly, decorationVisuals);
 }
Beispiel #8
0
        public async Task SelectGeometries(List <SqlGeometry> geometries, VisualParameters visualParameters, System.Windows.Media.Geometry pointSymbol = null)
        {
            Debug.WriteLine("SelectGeometries 675 start [MapPresenter]");
            await this.RequestSelectGeometries?.Invoke(geometries, visualParameters, pointSymbol);

            Debug.WriteLine("SelectGeometries 675 end [MapPresenter]");
        }
Beispiel #9
0
 public void AddGeometry(System.Windows.Media.Geometry param0)
 {
     throw new System.NotImplementedException();
 }
 public System.Windows.Media.IntersectionDetail FillContainsWithDetail(System.Windows.Media.Geometry param0)
 {
     throw new System.NotImplementedException();
 }
Beispiel #11
0
 protected override void OnRenderContent(System.Windows.Media.DrawingContext dc, Rect cellRect, System.Windows.Media.Geometry clipGeometry, DataColumnBase dataColumnBase, GridCell gridCell, object dataContext)
 {
     // Overridden to avoid the content to be drawn. Here, its loads  Image control as usual in UseLightweightTemplate true case also.
 }
        protected override void OnRenderContent(System.Windows.Media.DrawingContext dc, Rect cellRect, System.Windows.Media.Geometry clipGeometry, DataColumnBase dataColumnBase, GridCell gridCell, object dataContext)
        {
            // Overridden to avoid the content to be drawn when unbound row cell has templates.
            if (dataColumnBase.GridUnBoundRowEventsArgs.hasCellTemplate || dataColumnBase.GridUnBoundRowEventsArgs.hasEditTemplate)
            {
                return;
            }

            base.OnRenderContent(dc, cellRect, clipGeometry, dataColumnBase, gridCell, dataContext);
        }
Beispiel #13
0
 protected virtual new void OnDraw(System.Windows.Media.DrawingContext drawingContext, System.Windows.Input.StylusPointCollection stylusPoints, System.Windows.Media.Geometry geometry, System.Windows.Media.Brush fillBrush)
 {
 }