Example #1
0
        private void Panel_Paint(object sender, PaintEventArgs e)
        {
            lock (this)
            {
                if (bitmap == null || bitmap.Width == 0 || bitmap.Height == 0)
                {
                    return;
                }
                Bitmap bitmapNew = new Bitmap(bitmap);
                try
                {
                    if (Mirror.Checked)
                    {
                        bitmapNew.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    }

                    if (Scale2.Checked)
                    {
                        /* Keep the aspect ratio */
                        Rectangle rc      = (sender as PictureBox).ClientRectangle;
                        float     xscale  = (float)rc.Width / (float)bitmap.Width;
                        float     yscale  = (float)rc.Height / (float)bitmap.Height;
                        float     xyscale = (xscale < yscale) ? xscale : yscale;
                        int       width   = (int)(bitmap.Width * xyscale);
                        int       height  = (int)(bitmap.Height * xyscale);
                        rc.X      = (rc.Width - width) / 2;
                        rc.Y      = (rc.Height - height) / 2;
                        rc.Width  = width;
                        rc.Height = height;
                        e.Graphics.DrawImage(bitmapNew, rc);
                    }
                    else
                    {
                        e.Graphics.DrawImageUnscaled(bitmapNew, 0, 0);
                    }
                    HandsRecognition.SetBitmap(bitmapNew);
                }
                finally
                {
                    bitmapNew.Dispose();
                }
            }
        }