Retrieving binary back to image and from database and save into a folder using WPF

前端 未结 1 1123
不思量自难忘°
不思量自难忘° 2021-01-28 03:30

I have successfully converted image to binary and saved it into the database using linq to sql WPF and now i want to retrieve it back to image format and save it to a specific f

相关标签:
1条回答
  • 2021-01-28 04:23

    First of your code to read the image is way to complex, you're opening it as a Stream and reading well, all bytes. There's a method that does exactly that so you can replace your whole ConverImageToBinary method with

    img.image = File.ReadAllBytes(_txtFileName.Text);
    

    Also you never "converted" anything to anything, an image is just an array of bytes on disk, you've read it, saved it to the database, if you read it back and save it back (using this time File.WriteAllBytes) it will work just fine, so

    IF you want to write to the disk then just save the image back to disk as such:

    File.WriteAllBytes(@"d:\myfile.bmp",img.Image.ToArray()) ;
    

    And make sure you change the extention to match your file type (so bmp for a bitmap jpg for a jpeg etc)

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