Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit 96efc44

Browse files
committed
don't close parent memory streams until finished with image
1 parent 4a57126 commit 96efc44

1 file changed

Lines changed: 7 additions & 25 deletions

File tree

src/SocialBootstrapApi/ImageResizer/ImageService.cs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
using System.Linq;
55
using System.Security.Cryptography;
66
using System.Text;
7-
using Funq;
87
using ServiceStack.Common;
98
using ServiceStack.Common.Utils;
109
using ServiceStack.Common.Web;
1110
using ServiceStack.ServiceHost;
1211
using ServiceStack.ServiceInterface;
1312
using ServiceStack.Text;
14-
using ServiceStack.WebHost.Endpoints;
1513
using System.Drawing;
1614
using System.Drawing.Drawing2D;
1715

@@ -67,7 +65,7 @@ public object Post(Upload request)
6765
}
6866
}
6967

70-
return HttpResult.Redirect("/ImageResizer/");
68+
return HttpResult.Redirect("/");
7169
}
7270

7371
private void WriteImage(Stream ms)
@@ -168,13 +166,11 @@ public static Image Crop(Image Image, int newWidth, int newHeight, int startX =
168166
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
169167
g.DrawImage(Image, new Rectangle(0, 0, newWidth, newHeight), startX, startY, newWidth, newHeight, GraphicsUnit.Pixel);
170168

171-
using (var ms = new MemoryStream())
172-
{
173-
bmp.Save(ms, ImageFormat.Png);
174-
Image.Dispose();
175-
var outimage = Image.FromStream(ms);
176-
return outimage;
177-
}
169+
var ms = new MemoryStream();
170+
bmp.Save(ms, ImageFormat.Png);
171+
Image.Dispose();
172+
var outimage = Image.FromStream(ms);
173+
return outimage;
178174
}
179175
}
180176
}
@@ -183,21 +179,7 @@ public object Any(Reset request)
183179
{
184180
Directory.GetFiles(UploadsDir).ToList().ForEach(File.Delete);
185181
Directory.GetFiles(ThumbnailsDir).ToList().ForEach(File.Delete);
186-
return HttpResult.Redirect("/ImageResizer/");
187-
}
188-
}
189-
190-
public class AppHost : AppHostBase
191-
{
192-
public AppHost() : base("Image Resizer", typeof(AppHost).Assembly) { }
193-
public override void Configure(Container container) { }
194-
}
195-
196-
public class Global : System.Web.HttpApplication
197-
{
198-
protected void Application_Start(object sender, EventArgs e)
199-
{
200-
new AppHost().Init();
182+
return HttpResult.Redirect("/");
201183
}
202184
}
203185
}

0 commit comments

Comments
 (0)