Issue while saving image using savefiledialog

前端 未结 1 1426
遥遥无期
遥遥无期 2021-01-25 06:16

I\'m using savefiledialog to save an image. Canvas is picturebox and the loaded image is bitmap. When I try to save it the file is created but somehow corrupted. Cause when I tr

相关标签:
1条回答
  • 2021-01-25 06:34

    I was gonna ask why you have the line

    System.IO.FileStream fs =
        (System.IO.FileStream)saveFileDialog1.OpenFile();
    

    But as it turns out, that's exactly the line causing your problems. You are opening the file to a FileStream. While it's open, you use canvas.Image.Save to write the image to that same file.

    It throws an exception, but since you just write the exception to the console you don't see it.

    Just remove the line I mentioned and your code will work.

    0 讨论(0)
提交回复
热议问题