Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems overwriting (re-saving) image when it was set as image source
    primarykey
    data
    text
    <p>Good day all,</p> <p>I am having some trouble with image permissions.</p> <p>I am loading an image from file, resizing it and then saving it out to another folder. I am then displaying this like so:</p> <pre><code> uriSource = new Uri(Combine(imagesDirectoryTemp, generatedFileName), UriKind.Absolute); imgAsset.Source = new BitmapImage(uriSource); </code></pre> <p>This is working fine, the trouble comes if the user then selects another image immediately after and tries to save it over the original file.</p> <p>An exception is generated upon saving my image <code>"ExternalException: A generic error occurred in GDI+."</code></p> <p>After some playing around i have narrowed the error down to <code>imgAsset.Source = new BitmapImage(uriSource);</code> as removing this line and not setting the imagesource will allow me to overwrite this file many times.</p> <p>I have also tried setting the source to something else, before re-saving in the hope that the old reference would be disposed, this was not the case.</p> <p>How can i get past this error?</p> <p>Thanks, Kohan</p> <p><strong>Edit</strong> </p> <p>Now using this code i am not getting the exception however the image source is not updating. Also since i am not using a SourceStream, im not sure what i need to dispose of to get this working.</p> <pre><code> uriSource = new Uri(Combine(imagesDirectoryTemp, generatedFileName), UriKind.Absolute); imgTemp = new BitmapImage(); imgTemp.BeginInit(); imgTemp.CacheOption = BitmapCacheOption.OnLoad; imgTemp.UriSource = uriSource; imgTemp.EndInit(); imgAsset.Source = imgTemp; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload