private void launchTimeImageBox_MouseUp(object sender, MouseEventArgs e)
        {
            //Cursor.Clip = Rectangle.Empty;
            this.isMouseDown = false;
            if (this.isCuttingPicture)
            {
                DrawRectangleOnImageBox();

                // Save the picture.
                if ((this.launchTimeImageBox.Image.iplImage) != null && (this.launchTimeImageBox.Image.mat != null))
                {
                    DaVinciAPI.ImageInfo current = getCurrentFrame();
                    if (current.iplImage == null || current.mat == null)
                    {
                        return;
                    }

                    picFileName = GetPictureShotFileName();
                    if (current.iplImage != IntPtr.Zero)
                    {
                        Bitmap imgSave = DaVinciCommon.ConvertToBitmap(current.iplImage);
                        imgSave.Save(picFileName, ImageFormat.Png);
                        MessageBox.Show(picFileName + " has been saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                mouseRect             = Rectangle.Empty;
                this.isCuttingPicture = false;
                this.Cursor           = Cursors.Default;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pe"></param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (imageToDraw.iplImage != IntPtr.Zero)
            {
                using (Bitmap bmp = DaVinciCommon.ConvertToBitmap(imageToDraw.iplImage))
                {
                    IntPtr hbmp    = bmp.GetHbitmap();
                    IntPtr pTarget = pe.Graphics.GetHdc();
                    IntPtr pSource = CreateCompatibleDC(pTarget);
                    IntPtr pOrig   = SelectObject(pSource, hbmp);

                    SetStretchBltMode(pTarget, PaintStretchMode.STRETCH_HALFTONE);
                    StretchBlt(pTarget, 0, 0, this.ClientSize.Width, this.ClientSize.Height, pSource,
                               0, 0, bmp.Width, bmp.Height, PaintRasterOperations.SRCCOPY);

                    IntPtr pNew = SelectObject(pSource, pOrig);
                    DeleteObject(pNew);
                    DeleteDC(pSource);
                    pe.Graphics.ReleaseHdc(pTarget);
                    DeleteObject(hbmp);
                    //pe.Graphics.DrawImage(bmp, 0, 0, this.Width, this.Height);
                }
            }
        }
Esempio n. 3
0
        private void launchTimeImageBox_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.videoFile == null)
            {
                MessageBox.Show("No video file loaded!",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                this.Cursor = Cursors.Default;
                return;
            }
            //Cursor.Clip = Rectangle.Empty;
            this.isMouseDown = false;
            if (isCuttingStartPicture || isCuttingStopPicture ||
                isCuttingPicture)
            {
                DrawRectangleOnImageBox();

                // Save the picture.
                if ((this.launchTimeImageBox.Image.iplImage) != null && (this.launchTimeImageBox.Image.mat != null))
                {
                    string imageName = GetPictureShotFileName();
                    if (isCuttingStartPicture)
                    {
                        startImageName = imageName;
                    }
                    else if (isCuttingStopPicture)
                    {
                        stopImageName = imageName;
                    }

                    var    current = launchTimeImageBox.Image;
                    Bitmap imgSave = DaVinciCommon.ConvertToBitmap(current.iplImage);

                    //imgSave.Save(startImageName, ImageFormat.Png);

                    int width, height, offsetX, offsetY;
                    if (mouseRect.Width > 0)
                    {
                        width   = mouseRect.Width;
                        offsetX = mouseRect.Left;
                    }
                    else
                    {
                        width   = -mouseRect.Width;
                        offsetX = mouseRect.Right;
                    }
                    if (mouseRect.Height > 0)
                    {
                        height  = mouseRect.Height;
                        offsetY = mouseRect.Top;
                    }
                    else
                    {
                        height  = -mouseRect.Height;
                        offsetY = mouseRect.Bottom;
                    }
                    width   = (int)(width * imgSave.Width / (double)this.launchTimeImageBox.Width);
                    height  = (int)(height * imgSave.Height / (double)this.launchTimeImageBox.Height);
                    offsetX = (int)(offsetX * imgSave.Width / (double)this.launchTimeImageBox.Width);
                    offsetY = (int)(offsetY * imgSave.Height / (double)this.launchTimeImageBox.Height);

                    if (width == 0 || height == 0 || (width + offsetX) > imgSave.Width || (height + offsetY) > imgSave.Height ||
                        offsetX < 0 || offsetY < 0)
                    {
                        return;
                    }

                    Rectangle cloneRect   = new Rectangle(offsetX, offsetY, width, height);
                    var       cloneBitmap = imgSave.Clone(cloneRect, imgSave.PixelFormat);
                    if (IsImageBoxVertical())
                    {
                        cloneBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    }
                    cloneBitmap.Save(imageName);
                    MessageBox.Show(imageName + " has been saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                mouseRect = Rectangle.Empty;
                if (isCuttingStartPicture)
                {
                    isCuttingStartPicture = false;
                }
                else if (isCuttingStopPicture)
                {
                    isCuttingStopPicture = false;
                }
                else
                {
                    isCuttingPicture = false;
                }

                this.Cursor = Cursors.Default;
            }
        }