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

Commit

Permalink
don't close parent memory streams until finished with image
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Apr 14, 2013
1 parent 4a57126 commit 96efc44
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/SocialBootstrapApi/ImageResizer/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Funq;
using ServiceStack.Common;
using ServiceStack.Common.Utils;
using ServiceStack.Common.Web;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints;
using System.Drawing;
using System.Drawing.Drawing2D;

Expand Down Expand Up @@ -67,7 +65,7 @@ public object Post(Upload request)
}
}

return HttpResult.Redirect("/ImageResizer/");
return HttpResult.Redirect("/");
}

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

using (var ms = new MemoryStream())
{
bmp.Save(ms, ImageFormat.Png);
Image.Dispose();
var outimage = Image.FromStream(ms);
return outimage;
}
var ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Png);
Image.Dispose();
var outimage = Image.FromStream(ms);
return outimage;
}
}
}
Expand All @@ -183,21 +179,7 @@ public object Any(Reset request)
{
Directory.GetFiles(UploadsDir).ToList().ForEach(File.Delete);
Directory.GetFiles(ThumbnailsDir).ToList().ForEach(File.Delete);
return HttpResult.Redirect("/ImageResizer/");
}
}

public class AppHost : AppHostBase
{
public AppHost() : base("Image Resizer", typeof(AppHost).Assembly) { }
public override void Configure(Container container) { }
}

public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
new AppHost().Init();
return HttpResult.Redirect("/");
}
}
}

0 comments on commit 96efc44

Please sign in to comment.