Domanda

Ciao qualcuno sa come salvare un'immagine dal rettangolo che ho creato?

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

    }

Ho l'immagine desiderata che viene tagliata, ma non so come salvare .. apprezzerei molto di aiuto.

È stato utile?

Soluzione

In ogni caso, ho ottenuto io stesso, questa è la semplice sul evento click del pulsante.

button1_Click private void (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); 

    }

dove il test è la mia immagine bitmap originale dichiarato nel costruttore.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top