Im trying to write a image from a database to the hard drive and then read it back to the Image Control.
Im getting the error: The process could not access .........\temp.jpg because it is being used by another process
I
have a the same app in Winforms and there its simple just put
Picturebox.Image.Dispose before you attempt to write over the old file.
But in WPF it won't work. I have spent hours trying to figure this out,
tried to dispose a lot of resources and Google. But could not find
anything.
I don't want to read the picture to the memory because it uses a lot of it.
If someone could help me it would be appreciated, Thanks
my code is
| if (imageStorage.Source != null) |
| { |
| imageStorage.Source = null; |
| } |
| |
| FileStream FS1 = new FileStream("temp.jpg", FileMode.Create); |
| byte[] buff = (byte[])dRow[1]; |
| FS1.Write(buff, 0, buff.Length); |
| FS1.Close(); |
| FS1.Dispose(); |
| |
| BitmapImage image = new BitmapImage(); |
| image.BeginInit(); |
| image.UriSource = new Uri(Directory.GetCurrentDirectory() + "\\temp.jpg"); |
| |
| image.DecodePixelWidth = 200; |
| image.EndInit(); |
| |
| imageimageStorage.Source = image; |