Ejemplo n.º 1
0
 public void DrawSquare(MyVisual visual)
 {
     if (visual == null)
     {
         return;
     }
     using (var drawingContext = visual.RenderOpen())
     {
         RenderOptions.SetBitmapScalingMode(visual, BitmapScalingMode.HighQuality);
         if (ImgPath1 != null && ImgPath1.Length > 0)
         {
             try
             {
                 var bitmapImage = new BitmapImage();
                 bitmapImage.BeginInit();
                 bitmapImage.StreamSource = new MemoryStream((byte[])ImgPath1.Clone());
                 bitmapImage.EndInit();
                 bitmapImage.Freeze();
                 drawingContext.DrawImage(bitmapImage, new Rect(new Point(0.0, 0.0), new Size(CanvasMain.Width, CanvasMain.Height)));
             }
             catch
             {
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void DrawEyes()
 {
     if (LeftEye1.InArea)
     {
         using (var drawingContext = LeftEye1.RenderOpen())
         {
             var position = LeftEye1.Position;
             drawingContext.DrawLine(new Pen(Brushes.Green, 2.5), new Point(position.X, position.Y - 25.0),
                                     new Point(position.X, position.Y + 25.0));
             drawingContext.DrawLine(new Pen(Brushes.Green, 2.5), new Point(position.X - 25.0, position.Y),
                                     new Point(position.X + 25.0, position.Y));
         }
     }
     if (!RightEye1.InArea)
     {
         return;
     }
     using (var drawingContext = RightEye1.RenderOpen())
     {
         var position = RightEye1.Position;
         drawingContext.DrawLine(new Pen(Brushes.Green, 2.5), new Point(position.X, position.Y - 25.0),
                                 new Point(position.X, position.Y + 25.0));
         drawingContext.DrawLine(new Pen(Brushes.Green, 2.5), new Point(position.X - 25.0, position.Y),
                                 new Point(position.X + 25.0, position.Y));
     }
 }
Ejemplo n.º 3
0
 public void SelectArea()
 {
     if (SelectionBorder1 == null || !CanvasMain.Contains(SelectionBorder1))
     {
         return;
     }
     using (var drawingContext = SelectionBorder1.RenderOpen())
     {
         var rect = new Rect(0.0, 0.0, CanvasMain.Width, CanvasMain.Height);
         drawingContext.DrawRectangle(Brushes.Transparent, new Pen
         {
             Brush     = Brushes.Blue,
             Thickness = 0.8,
             DashStyle = DashStyles.Dot
         }, new Rect(SelectionBorder1.StartPoint, SelectionBorder1.NextPoint));
     }
 }
Ejemplo n.º 4
0
        public void rdbCutArea_Click(object sender, RoutedEventArgs e)
        {
            if (!CanvasMain.Contains(SelectionBorder1) || !(SelectionBorder1.StartPoint != SelectionBorder1.NextPoint))
            {
                return;
            }
            IsChanged             = true;
            TranslateTransform1.X = 0.0;
            TranslateTransform1.Y = 0.0;
            CanvasMain.Clear();
            if (Scrollingcount > 0)
            {
                SelectionBorder1.StartPoint = new Point(
                    SelectionBorder1.StartPoint.X / Math.Pow(ZoomScale, Math.Abs(Scrollingcount)),
                    SelectionBorder1.StartPoint.Y / Math.Pow(ZoomScale, Math.Abs(Scrollingcount)));
                SelectionBorder1.NextPoint = new Point(SelectionBorder1.NextPoint.X / Math.Pow(ZoomScale, Math.Abs(Scrollingcount)),
                                                       SelectionBorder1.NextPoint.Y / Math.Pow(ZoomScale, Math.Abs(Scrollingcount)));
            }
            else if (Scrollingcount < 0)
            {
                SelectionBorder1.StartPoint = new Point(
                    SelectionBorder1.StartPoint.X * Math.Pow(ZoomScale, Math.Abs(Scrollingcount)),
                    SelectionBorder1.StartPoint.Y * Math.Pow(ZoomScale, Math.Abs(Scrollingcount)));
                SelectionBorder1.NextPoint = new Point(SelectionBorder1.NextPoint.X * Math.Pow(ZoomScale, Math.Abs(Scrollingcount)),
                                                       SelectionBorder1.NextPoint.Y * Math.Pow(ZoomScale, Math.Abs(Scrollingcount)));
            }
            var bitmap = new Bitmap((int)Math.Abs(SelectionBorder1.NextPoint.X - SelectionBorder1.StartPoint.X),
                                    (int)Math.Abs(SelectionBorder1.NextPoint.Y - SelectionBorder1.StartPoint.Y));

            Graphics.FromImage(bitmap);
            var x      = (int)SelectionBorder1.StartPoint.X;
            var y      = (int)SelectionBorder1.StartPoint.Y;
            var width  = (int)Math.Abs(SelectionBorder1.StartPoint.X - SelectionBorder1.NextPoint.X);
            var height = (int)Math.Abs(SelectionBorder1.StartPoint.Y - SelectionBorder1.NextPoint.Y);

            if (SelectionBorder1.NextPoint.X < SelectionBorder1.StartPoint.X)
            {
                x = (int)SelectionBorder1.NextPoint.X;
            }
            if (SelectionBorder1.NextPoint.Y < SelectionBorder1.StartPoint.Y)
            {
                y = (int)SelectionBorder1.NextPoint.Y;
            }
            var sourceRect = new Int32Rect(x, y, width, height);

            try
            {
                var myVisual = new MyVisual();
                using (var drawingContext = myVisual.RenderOpen())
                {
                    myVisual.Clip = new RectangleGeometry(new Rect(0.0, 0.0, width, height));
                    var memoryStream = new MemoryStream(ImgDefaultPath1);
                    var bitmapImage  = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmapImage.StreamSource = memoryStream;
                    bitmapImage.EndInit();
                    bitmapImage.Freeze();
                    var croppedBitmap = new CroppedBitmap(bitmapImage, sourceRect);
                    drawingContext.DrawImage(croppedBitmap, new Rect(0.0, 0.0, sourceRect.Width, sourceRect.Height));
                    memoryStream.Close();
                }
                try
                {
                    var str = (string)(object)Guid.NewGuid() + (object)".bmp";
                    SaveImage(myVisual, width, height, MainForm.ApplicationData + str);
                    var fileStream = new FileStream(MainForm.ApplicationData + str, FileMode.Open);
                    ImgPath1 = new byte[fileStream.Length];
                    ImgPath1 = (byte[])ImgPath1.Clone();
                    fileStream.Read(ImgPath1, 0, (int)fileStream.Length);
                    fileStream.Close();
                    File.Delete(MainForm.ApplicationData + str);
                }
                catch
                {
                }
                ImgDefaultPath1             = (byte[])ImgPath1.Clone();
                ImgChangedImage             = (byte[])ImgPath1.Clone();
                SelectionBorder1.StartPoint = new Point(0.0, 0.0);
                SelectionBorder1.NextPoint  = new Point(0.0, 0.0);
                LeftEye1.InArea             = false;
                RightEye1.InArea            = false;
                CanvasMain.Width            = bitmap.Width;
                CanvasMain.Height           = bitmap.Height;
                VsFace1      = new MyVisual();
                VsFace1.Type = MyVisualType.Image;
                CanvasMain.AddVisual(VsFace1);
                Scrollingcount = 0;
                SelectArea();
                DrawSquare(VsFace1);
            }
            catch (Exception ex)
            {
                var num = (int)XtraMessageBox.Show(ex.Message, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }