Note that there are some explanatory texts on larger screens.

plurals
  1. POImageResizer disposing provided Image reference
    text
    copied!<p>We are using the image resizer from imageresizing.net and are seeing some weird behaviour.</p> <p>When we read an image in from a stream and then resize the image we can no longer access the properties of the original image.</p> <p>The following code will reproduce the issue.</p> <pre><code> static void Main(string[] args) { using(var httpPostedFileBaseImage = new FileStream(@"C:\test.jpg",FileMode.Open, FileAccess.Read, FileShare.Read)) { using(var uploadedImage = Image.FromStream(httpPostedFileBaseImage)) { Console.WriteLine(uploadedImage.Width); var resizedImage = ImageBuilder.Current.Build(uploadedImage, new ResizeSettings("width=110;height=83")); Console.WriteLine(uploadedImage.Width); } } } </code></pre> <p>Before the ImageBuilder line we are able to see the uploadedImage.Width fine but afterwards it throws an exception:</p> <pre><code>System.ArgumentException was unhandled HResult=-2147024809 Message=Parameter is not valid. Source=System.Drawing StackTrace: at System.Drawing.Image.get_Width() at ConsoleApplication6.Program.Main(String[] args) in C:\Users\Daniel\Desktop\ConsoleApplication6\ConsoleApplication6\Program.cs:line 25 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: </code></pre> <p>Is there something that we are doing wrong here or could this possibly be a bug in the image resizer?</p> <p>Note: the problem was originally from an asp.net mvc app that has images uploaded which is why the variable is called httpPostedFileBaseImage and we are using Image.FromStream instead of perhaps Image.FromFile</p> <p>The image is <img src="https://i.stack.imgur.com/vxPHL.png" alt="enter image description here"> but it appears to happen on most images.</p> <p>EDIT:</p> <p>Tried the following after the image resizing to no avail</p> <pre><code>httpPostedFileBaseImage.Seek(0, SeekOrigin.Begin); </code></pre> <p>EDIT2:</p> <p>This is what confused me <img src="https://i.stack.imgur.com/MjxMi.png" alt="enter image description here"></p> <p>The documentation seems to suggest that "it will not be disposed unless disposeSource=true, or am I misreading this?</p>
 

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