Hi Dear, You have to three methods as like under
private void PicCapPhoto_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
cropX = e.X;
cropY = e.Y;
cropPen = new Pen(cropPenColor, cropPenSize);
cropPen.DashStyle = DashStyle.DashDotDot;
Cursor = Cursors.Cross;
}
picCapture.Refresh();
}
catch (Exception ex)
{
}
}
private void PicCapPhoto_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
if (PicCapPhoto.Image == null)
return;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
PicCapPhoto.Refresh();
cropWidth = e.X - cropX;
cropHeight = e.Y - cropY;
PicCapPhoto.CreateGraphics().DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight);
}
}
catch (Exception ex)
{
return;
}
}
private void PicCapPhoto_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
Cursor = Cursors.Default;
if (cropWidth < 1)
{
return;
}
Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);
Bitmap bit = new Bitmap(PicCapPhoto.Image, PicCapPhoto.Width, PicCapPhoto.Height);
cropBitmap = new Bitmap(cropWidth, cropHeight);
Graphics g = Graphics.FromImage(cropBitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel);
msnew = new MemoryStream();
cropBitmap.Save(msnew, System.Drawing.Imaging.ImageFormat.Jpeg);
PictureBox1.Image = cropBitmap;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error in Generate photo", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
It Will Work fine.
Mahesh Patel
MCA-2012
09924625962