简体   繁体   中英

C# WPF Generating image access denied

So what I'm trying to to is generating a screenshot of a specific camera stream. The support of the camera sent me this code but for some reason it has no access to the specific path. The path is also a folder in the project folder and writing to it is noramlly not a problem. I can write JSON file to this path.

using (var fileStream = new FileStream(@"C:/Users/Kimeru/Documents/Dermalog Noah WPF/images", FileMode.Create))
{
    var encoder = new PngBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(detectionResult.RGBImage.ToBitmapSource()));
    encoder.Save(fileStream);
}

detectionResult.RGBImage is a call from the sdk to get the image, this shouldn't be the problem. Also I have tried changing priveleges of the folders and the project to administartor and other users. Nothings seems to work, and I still can't get access to this path.

@"C:/Users/Kimeru/Documents/Dermalog Noah WPF/images" is apparently a folder path.

You need to add the name of the file you want to write to:

var folder = @"C:/Users/Kimeru/Documents/Dermalog Noah WPF/images";
var file = "image1.png";
var path = Path.Combine(folder, file);

using (var fileStream = new FileStream(path, FileMode.Create))
{
    var encoder = new PngBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(detectionResult.RGBImage.ToBitmapSource()));
    encoder.Save(fileStream);
}

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