简体   繁体   中英

How to Save the Captured Image from Webcam into Project Folder/Specific Folder

I'm trying to save the picturebox image that has been captured using the Webcam. I'm using AForget.NET.

What i want to do is I want that picturebox image to be saved into Project/Specific Folder when i click Ok button and get that path that has been save to folder.

I'm getting error of GDI +

Here's my Code

RegisterCustomer _regCustomer;

    public UpdateImageCapture(RegisterCustomer regCustomer)
    {
        InitializeComponent();
        _regCustomer = regCustomer;
    }

    ImageHelper img = new ImageHelper();

    private void ImageCapture_Load(object sender, EventArgs e)
    {

        img.ImageSettings
        (
            img._captureDevice,
            img.finalFrame,
            cboxWebcamType
        );

        img.finalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);

        btnOk.Hide();
        btnCancel.Hide();
    }

private void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
        picPreviewImage.Image = (Bitmap)eventArgs.Frame.Clone();
}

These code specify that when the button capture is clicked the picCaptureImage(Picturebox2) will get the clone copy of picPreviewImage(Picturebox1)

NOTE: Picturebox1 show yourself from a webcam

private void BtnCapture_Click(object sender, EventArgs e)
{
        picCapturedImage.Image = (Bitmap)picPreviewImage.Image.Clone();
        picCapturedImage.BringToFront();
        btnCapture.Hide();
        btnOk.Show();
        btnCancel.Show();
}

private void BtnOk_Click(object sender, EventArgs e)
{
   if (picCapturedImage.Image != null)
        {
            var bitmap = new Bitmap(picCapturedImage.Image);
            var newBitmap = new Bitmap(bitmap);
            bitmap.Save(@"C:\Users\dieth\source\repos\SalesInventorySystem\SalesInventorySystem\Resources", ImageFormat.Png);
            bitmap.Dispose();
            bitmap = null;
        }
        else {
            MessageBox.Show("NULL");
        }
}

I solved it , but when i tried to capture an image again , it just replacing the image from that file.

if (picCapturedImage.Image != null)
            picCapturedImage.Image.Save(@"..\..\Resources\ImageCapture.Png", ImageFormat.Png);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM