Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
i have a paint control for drawing.
i want cut of a picture were drawed in paint control
x1=>first of draw in paint control
x2=>end of draw in paint control

            Rectangle rec = new Rectangle(paint_Control1.X1, 0,
paint_Control1.X2 - paint_Control1.X1, paint_Control1.Height);
            Bitmap bmp = new Bitmap(paint_Control1.X2 - paint_Control1.X1,  paint_Control1.Height);
            paint_Control1.DrawToBitmap(bmp, rec);


-----------------
problem=>the slicing is not begin from X1. slicing begin from first of control
Posted
Updated 24-Jun-11 19:32pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Jun-11 1:12am    
"First of control"... what does it mean?
--SA
jiji2663 25-Jun-11 1:16am    
my control Width=534 and Height=91
for example i drawing from Width=200 to Width=250
the slicing beginig from Width=534

1 solution

Try:
public static Bitmap Extract(Bitmap src, Rectangle section)
    {
    Bitmap bmp = new Bitmap(section.Width, section.Height);
    using (Graphics g = Graphics.FromImage(bmp))
        {
        g.DrawImage(src, 0, 0, section, GraphicsUnit.Pixel);
        }
    return bmp;
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900