views:

99

answers:

1

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 .

A: 

anyhow, i got it myself, this is the simple one on button click event.

private void button1_Click(object sender, EventArgs e) { Bitmap lol = new Bitmap(100, 100); ;

        GraphicsUnit units = GraphicsUnit.Pixel;
        System.Drawing.Imaging.ImageAttributes imageAttr = new System.Drawing.Imaging.ImageAttributes();

        Graphics gx = Graphics.FromImage(lol);


        int width = testing.Width / 3;
        int height = testing.Height / 3;
        Rectangle destrect1 = new Rectangle(0, 0, width, height);
           //1.1.jpg//
        gx.DrawImage(testing, destrect1, 0, 0, width, height, units, imageAttr);

        pictureBox2.Image = lol;
        lol.Save(@"Pictures\\hahaha.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
       // pictureBox2.Image = gx.(lol); 

    }

where testing is my original bitmap image declared in constructor.

cheesebunz