Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating wpf application. I am showing the preview image(which is taken by cam) in Image control. The image get saved by default. If the user want to retake the photo i am deleting the current image.

int imageCount = Directory.GetFiles(imgDir, "*",SearchOption.TopDirectoryOnly).Length;

  ImageFormat imgFormat = (ImageFormat)GetValue(SnapshotFormatProperty);

   string filePath = Path.Combine(imgDir, "IMAGE_" + ++imageCount + ".Jpeg");

                using (Bitmap bmp = new Bitmap(panelWidth, panelHeight))
                {
                    using (Graphics graphics = Graphics.FromImage(bmp))
                    {
                        // image
                    }
                    bmp.Save(filePath, imgFormat);
                }
                globalFilePath = filePath;


showing image in Image Control
C#
string strUri = String.Format(WebCamControl.globalFilePath);
           previewImage.Source = BitmapFromUri(new Uri(strUri));


C#
public static ImageSource BitmapFromUri(Uri source)
        {
            var bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = source;
            bitmap.CacheOption = BitmapCacheOption.OnLoad;
            bitmap.EndInit();
            return bitmap;
        }



previewImage.Source = null;

C#
if (System.IO.File.Exists(WebCamControl.globalFilePath))
                {
                    System.IO.File.Delete(WebCamControl.globalFilePath);
                }
                else
                {
                    MessageBox.Show("File Not Exists");
                }



After Completing this process when i take the new image the Image control shows the previous image which was deleted. Is the Image Control caching the previus Image??Kindly give me the solution.
Posted
Updated 24-Feb-15 23:16pm
v2

1 solution

I suppose, BitmapCacheOption.OnLoad does it: "Caches the entire image into memory at load time. All requests for image data are filled from the memory store."
Try None instead
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900