Skip to content
Permalink
Browse files

don't close parent memory streams until finished with image

  • Loading branch information...
mythz committed Apr 14, 2013
1 parent 4a57126 commit 96efc4414c8d5f23b0b602208316c4236b2d8fcf
Showing with 7 additions and 25 deletions.
  1. +7 −25 src/SocialBootstrapApi/ImageResizer/ImageService.cs
@@ -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;

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

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

private void WriteImage(Stream ms)
@@ -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;
}
}
}
@@ -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.
You can’t perform that action at this time.