Forum guidelines
  • Home
  • »
  • Windows Forms
  • »
  • Crop area selection control(like photoshop's) in c# windows form
AuthorQuestion
Crop area selection control(like photoshop's) in c# windows form
Posted By learner learner on 07 Mar 2012
how to develop a crop selection control like photoshop's in c# 4.0 in widows form application.
 
I have a windows form application in c# 4.0 that can crop images. At first you have to draw a rectangle using mouse to select the cropped region.

 private Point _pt;
 
private Point _pt2;
   
private void picBoxImageProcessing_MouseDown(object sender, MouseEventArgs e)
   
{

   
if (e.Button == MouseButtons.Left)
   
{
       
int ix = (int)(e.X / _zoom);
       
int iy = (int)(e.Y / _zoom);

       
//reset _pt2
       _pt2
= new Point(0, 0);
       _pt
= new Point(ix, iy);

       
// pictureBox1.Invalidate();
       picBoxImageProcessing
.Invalidate();
   
}
}

 
private void picBoxImageProcessing_MouseUp(object sender, MouseEventArgs e)
 
{
   
if (e.Button == MouseButtons.Left && _selecting)
   
{
       _selecting
= false;
   
}
 
}

 
private void picBoxImageProcessing_Paint(object sender, PaintEventArgs e)
 
{


     
if (_selecting &&_pt.X >= 0 && _pt.Y >= 0 && _pt2.X >= 0 && _pt2.Y >= 0)
       
{

            e
.Graphics.DrawRectangle(pen, _pt.X * _zoom, _pt.Y * _zoom,
                     
(_pt2.X - _pt.X)          *         _zoom, (_pt2.Y - _pt.Y) * _zoom);
         
}
   
}

       
private void picBoxImageProcessing_MouseMove(object sender, MouseEventArgs e)
     
{


       
if (e.Button == MouseButtons.Left)
       
{
         _selecting
= true;
         
int ix = (int)(e.X / _zoom);
         
int iy = (int)(e.Y / _zoom);

         _pt2
= new Point(ix, iy);

         
//  pictureBox1.Invalidate();
           picBoxImageProcessing
.Invalidate();
         
}
     
}

there is no problem to draw the rectangle by mouse dragging. But if i want to change the height or width of the rectangle then I have to draw a new rectangle, that i don't want. I want to change the height and width of the rectangle by modifying the drawn rectangle instead of drawing a new rectangle.

I don't want to know how to crop. I need to draw a resizable rectangle on the image as we can do in photoshop.

So I need a crop selection control like photoshop's crop control.




SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.