✅ A generic error occurred in GDI+.' -> Save Image Path

Hey, I been trying to making some face recognition using EMGU.CV, but I faces a problem which, when I'm trying to save the picture, which the cropped side (faces) so I could using that to face recognition in future, but when I'm trying to save it by binding to button1, it give me a problem -> System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.' .

 private int faceCounter = 0;
 private void button1_Click(object sender, System.EventArgs e)
 {

     if (pictureBox2.Image != null)
     {
 
         string savePath = Application.StartupPath + "/TrainedFaces/face" + faceCounter + ".bmp";
         pictureBox2.Image.Save(savePath, System.Drawing.Imaging.ImageFormat.Bmp);

         faceCounter++;

         MessageBox.Show("Cropped face saved successfully.");
     }
     else
     {
         MessageBox.Show("No face detected to save.");
     }
 }

  private async Task StreamVideo2()
{
    var faceCasade = new        CascadeClassifier("./detection/haarcascade_frontalface_default.xml");
    var vc = new VideoCapture(0, Emgu.CV.VideoCapture.API.DShow);

    var faces = faceCasade.DetectMultiScale(frameGray, 1.3, 5);
    while (streamVideo)
    {
....

....
        pictureBox2.Image = grayCroppedFace.ToBitmap();
....
        var img = frame.ToBitmap();
        pictureBox1.Image = img;


.....
    }
} 
image.png
Was this page helpful?