• 0
  • 1
  • 0

Image Control problem

Jan 10 2009 11:00 AM
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); 
                BitmapImage image = new BitmapImage(); 
                image.UriSource = new Uri(Directory.GetCurrentDirectory() + "\\temp.jpg"); 
                image.DecodePixelWidth = 200
                imageimageStorage.Source = image; 

Answers (1)