C# Image saving from onPaint method

Posted by cheesebunz on Stack Overflow See other posts from Stack Overflow or by cheesebunz
Published on 2010-05-25T04:21:47Z Indexed on 2010/05/25 4:41 UTC
Read the original article Hit count: 322

Filed under:
|
|
|

Hi anyone knows how to save an image from the rectangle i created?

    protected override void OnPaint(PaintEventArgs e)
    {
        Bitmap bitmap = new Bitmap(@"Pictures/testing.jpg");
        Image img = bitmap;

       int width = testing.Width / 3;
       int height = testing.Height / 3;
       Rectangle destrect = new Rectangle(0, 0, width, height);
       GraphicsUnit units = GraphicsUnit.Pixel;
       System.Drawing.Imaging.ImageAttributes imageAttr= new System.Drawing.Imaging.ImageAttributes();

        //1.1.jpg//
       //e.Graphics.DrawImage(img,destrect,0,0, width, height, units, imageAttr);

        //1.2.jpg//
      e.Graphics.DrawImage(img, destrect, width, 0,width, height, units, imageAttr);

        base.OnPaint(e);

    }

I have the desired image that is cropped but i don't know how to save .. Would greatly appreciate any help .

© Stack Overflow or respective owner

Related posts about c#

Related posts about image