WinForm PictureBox reading an image file cannot be released

Source: Internet
Author: User

Today to do a photo program, the camera SDK everything is done, just to display the image and save the photo step card for half a day.

The reason is that the preview image uses PictureBox and the image file is loaded in the following way:

  Pictureboxphoto.image = Image.FromFile (filepath);

However, this will cause the image file to remain in the occupied state, once the photo completion needs to overwrite the source map, because the file operation is not released can not be overwritten.

Before looking at various programs, what deep copy is on, and finally found that using FileStream to operate the most effective.

Replace the previous code:

using New FileStream (filepath, FileMode.Open, FileAccess.Read))                     = Image.fromstream (Lstream);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.