コード例 #1
0
 public void rdbOpen1_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         CanvasMain.Cursor = Cursors.Arrow;
         var openFileDialog = new OpenFileDialog();
         openFileDialog.Filter = "Image Files (*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF)|*.BMP;*.JPG;*.GIF;*.TIFF;*.TIF;*.png;*.jpeg";
         if (openFileDialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         ImgSource1 = null;
         Mainform.btBrightness.EditValue = 0;
         Mainform.btContrast.EditValue   = 0;
         Mainform.btSize.EditValue       = 100;
         IsChanged      = true;
         Scrollingcount = 0;
         CanvasMain.Clear();
         VsFace1      = new MyVisual();
         VsFace1.Type = MyVisualType.Image;
         var fileStream = new FileStream(openFileDialog.FileName, FileMode.Open);
         var numArray   = new byte[fileStream.Length];
         fileStream.Read(numArray, 0, numArray.Length);
         ImgSource1 = (byte[])numArray.Clone();
         LoadImage(numArray);
         fileStream.Close();
     }
     catch (Exception ex)
     {
         ImgPath1 = null;
         var num = (int)MessageBox.Show(ex.Message, Messages.Error, MessageBoxButton.OK, MessageBoxImage.Hand);
     }
 }
コード例 #2
0
 public void rdbEye_Click(object sender, RoutedEventArgs e)
 {
     CanvasMain.Cursor = Cursors.Cross;
     if (!Mainform.btEye.Down)
     {
         _allowDrawEyes = false;
         CanvasMain.DeleteVisual(LeftEye1);
         CanvasMain.DeleteVisual(RightEye1);
     }
     else if (ImgDefaultPath1 != null && ImgDefaultPath1.Length > 0)
     {
         try
         {
             CanvasMain.DeleteVisual(LeftEye1);
             CanvasMain.DeleteVisual(RightEye1);
         }
         catch
         {
         }
         LeftEye1  = new MyVisual();
         RightEye1 = new MyVisual();
         CanvasMain.DeleteVisual(LeftEye1);
         CanvasMain.DeleteVisual(RightEye1);
         if (Face.DetectAllFaces(new Bitmap(new MemoryStream((byte[])ImgPath1.Clone())).ConvertFrom(), null).Length == 0)
         {
             _allowDrawEyes =
                 XtraMessageBox.Show(Messages.NoFaceWasFoundDoYouWantToSet, Messages.Message, MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question) == DialogResult.Yes;
         }
     }
 }
コード例 #3
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
             {
             }
         }
     }
 }
コード例 #4
0
 public void LoadImage(byte[] stream)
 {
     try
     {
         Mainform.btBrightness.Value = 0;
         Mainform.btContrast.Value   = 0;
         Mainform.btSize.Value       = 100;
         ImgSource1 = stream;
         IsChanged  = true;
         CanvasMain.Clear();
         Scrollingcount  = 0;
         VsFace1         = new MyVisual();
         VsFace1.Type    = MyVisualType.Image;
         ImgPath1        = new byte[stream.Length];
         ImgPath1        = (byte[])stream.Clone();
         ImgDefaultPath1 = (byte[])ImgPath1.Clone();
         ImgChangedImage = (byte[])ImgPath1.Clone();
         var bitmapImage = new BitmapImage();
         bitmapImage.BeginInit();
         bitmapImage.StreamSource = new MemoryStream((byte[])ImgDefaultPath1.Clone());
         bitmapImage.EndInit();
         bitmapImage.Freeze();
         CanvasMain.Width  = bitmapImage.PixelWidth;
         CanvasMain.Height = bitmapImage.PixelHeight;
         if (ScrollViewer1.ActualWidth > CanvasMain.Width)
         {
             TranslateTransform1.X = (ScrollViewer1.ActualWidth - CanvasMain.Width) / 2.0;
         }
         if (ScrollViewer1.ActualHeight > CanvasMain.Height)
         {
             TranslateTransform1.Y = (ScrollViewer1.ActualHeight - CanvasMain.Height) / 2.0;
         }
         CanvasMain.AddVisual(VsFace1);
         DrawSquare(VsFace1);
         if (!Mainform.btEye.Down)
         {
             return;
         }
         rdbEye_Click(new object(), new RoutedEventArgs());
     }
     catch
     {
     }
 }
コード例 #5
0
        public MyVisual GetVisual()
        {
            MyVisual myVisual = new MyVisual();

            myVisual.ShowText   = ShowText;
            myVisual.LineColor  = LineColor;
            myVisual.ForeColor  = ForeColor;
            myVisual.LineWidth  = LineWidth;
            myVisual.FontName   = FontName;
            myVisual.FontSize   = FontSize;
            myVisual.FormNumber = FormNumber;
            myVisual.Position   = _Position;
            myVisual.Type       = Type;
            myVisual.Points.AddRange((Point[])Points.ToArray().Clone());
            myVisual.NextPoint      = NextPoint;
            myVisual.StartPoint     = StartPoint;
            myVisual.InArea         = InArea;
            myVisual.BlocText       = BlocText;
            myVisual.StartLinePoint = StartLinePoint;
            return(myVisual);
        }
コード例 #6
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);
            }
        }
コード例 #7
0
        public void canvasMain_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var position1 = e.GetPosition(CanvasMain);

            if (e.LeftButton == MouseButtonState.Pressed && Mainform.btEye.Down && _allowDrawEyes)
            {
                var myVisual = (MyVisual)CanvasMain.GetVisual(position1);
                if (LeftEye1.InArea && RightEye1.InArea)
                {
                    IsChanged = true;
                    if (myVisual == LeftEye1)
                    {
                        Left1Drag   = true;
                        ClickOffset = new Point(myVisual.Position.X - 20.0, myVisual.Position.Y - 20.0) - position1;
                    }
                    else if (myVisual == RightEye1)
                    {
                        Right1Drag  = true;
                        ClickOffset = new Point(myVisual.Position.X - 20.0, myVisual.Position.Y - 20.0) - position1;
                    }
                }
                else if (!LeftEye1.InArea && !RightEye1.InArea)
                {
                    LeftEye1 = new MyVisual();
                    CanvasMain.AddEye(LeftEye1);
                    IsChanged         = true;
                    LeftEye1.InArea   = true;
                    LeftEye1.Position = position1;
                }
                else if (LeftEye1.InArea && !RightEye1.InArea)
                {
                    var position2 = LeftEye1.Position;
                    if (position2.X > position1.X)
                    {
                        RightEye1          = new MyVisual();
                        RightEye1.InArea   = true;
                        RightEye1.Position = LeftEye1.Position;
                        LeftEye1.Position  = position1;
                        CanvasMain.AddEye(RightEye1);
                        IsChanged = true;
                    }
                    else
                    {
                        position2 = LeftEye1.Position;
                        if (position2.X < position1.X)
                        {
                            RightEye1          = new MyVisual();
                            RightEye1.InArea   = true;
                            RightEye1.Position = position1;
                            CanvasMain.AddEye(RightEye1);
                        }
                    }
                }
                DrawEyes();
            }
            else
            {
                CanvasMain.DeleteVisual(SelectionBorder1);
                SelectionBorder1            = new MyVisual();
                SelectionBorder1.Type       = MyVisualType.SelectImageRect;
                SelectionBorder1.StartPoint = e.GetPosition(CanvasMain);
                SelectionBorder1.NextPoint  = e.GetPosition(CanvasMain);
                CanvasMain.AddVisual(SelectionBorder1);
                IsChanged = true;
            }
        }