/* Gestion du mouvement du curseur pour la sélection de la zone - Projeté 3D */ private void PB_P3D_MouseMove(object sender, MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == System.Windows.Forms.MouseButtons.Left) { PB_IMG_P3D.Refresh(); /* set width and height for crop rectangle. */ rectW = e.X - crpX; rectH = e.Y - crpY; Graphics g = PB_IMG_P3D.CreateGraphics(); g.DrawRectangle(crpPen, crpX, crpY, rectW, rectH); g.Dispose(); } }
/* Fonction pour exploiter la zone sélectionnée - Projeté 3D */ private void Crop_P3D_Click(object sender, EventArgs e) { Cursor = Cursors.Default; Bitmap bmp3 = new Bitmap(PB_IMG_P3D.Width, PB_IMG_P3D.Height); PB_IMG_P3D.DrawToBitmap(bmp3, PB_IMG_P3D.ClientRectangle); Bitmap crpImg = new Bitmap(rectW, rectH); for (int i = 0; i < rectW; i++) { for (int y = 0; y < rectH; y++) { Color pxlclr = bmp3.GetPixel(crpX + i, crpY + y); crpImg.SetPixel(i, y, pxlclr); } } /* Affichage de l'image "croppée" dans la PictureBox PB_Preview_P3D */ PB_Preview_P3D.Image = (Image)crpImg; PB_Preview_P3D.SizeMode = PictureBoxSizeMode.StretchImage; }