C # Сохранение изображения из метода onPaint - PullRequest
0 голосов
/ 25 мая 2010

Привет, кто-нибудь знает, как сохранить изображение из созданного мною прямоугольника?

    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);

    }

У меня есть нужное изображение, которое обрезается, но я не знаю, как его сохранить. Буду очень признателен за любую помощь.

1 Ответ

0 голосов
/ 25 мая 2010

Во всяком случае, я получил это сам, это простое событие при нажатии кнопки.

private void button1_Click (отправитель объекта, 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); 

    }

где тестирование - это мое исходное растровое изображение, объявленное в конструкторе.

...