2010-02-01 2 views
2

나는 모든 사람들이 폴더가 너무GDI + 일반 오류 ASP.NET MVC

public ImageResult ProfileAsset(string profile, int width, int height) { 
      PhotoDB imgstr = new PhotoDB(); 

      Image FullsizeImage = Image.FromFile(
       imgstr.getFilePath(profile, false, PhotoDB.PhotoSize.None) 
       ); 


      Image cropedImage = imgstr.Crop(FullsizeImage, width, width, PhotoDB.AnchorPosition.Center); 
      return new ImageResult { Image = cropedImage, ImageFormat = ImageFormat.Png }; 
     } 

나처럼 읽어되고있는 이미지 파일이 들어 있는지 확인되는 말씀을 내가 해봤 GDI + 일반 오류가 오전 해당 폴더에 대한 사용 권한을 모든 사람에게 설정했지만 여전히이 오류가 발생합니까?

왜 그런가?

A generic error occurred in GDI+. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +378002 System.Drawing.Image.Save(Stream stream, ImageFormat format) +36
Havana.ImageResult.ExecuteResult(ControllerContext context) in C:\DropBox\My Dropbox\Havana\Havana.MVC\Infrastructure\ImageResult.cs:44 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10
System.Web.Mvc.<>c__DisplayClass11.b__e() +20 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func 1 continuation) +251 System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList 1 filters, ActionResult actionResult) +178
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399 System.Web.Mvc.Controller.ExecuteCore() +126 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

답변

2

은 내가 당신이에서 이미지를 읽고있는 폴더에 대한 보안 권한을 손가락의 점을 발견 한 물건이에 대한 해결책, 엄지 손가락의 일반적 규칙 및 모든를 발견했다. 그러나 이것이 항상 그런 것은 아닙니다.

실제로 원격 액세스를 통해 서버에 올라갈 때까지는 아니며 코드를 통해 GDI + 일반 예외를 얻는 곳을 확인했습니다 ... Rick에 대한 훌륭한 기사를 찾을 수있었습니다. 내 솔루션 Strahl의 블로그. Common problems with rendiering bitmaps into ASP.NET Output stream

기본적으로 원본 개체를 처리 할 때 반드시 처리해야합니다. 내가 그것을 사용하고 나는 그것을 폐기 croppedImage에 넣어 후에 내 ImageResult 활동에 예를 들어 내가이

Image FullsizeImage = Image.FromFile(
     imgstr.getFilePath(profile, false, PhotoDB.PhotoSize.None) 
     ); 


    Image cropedImage = imgstr.Crop(FullsizeImage, width, width, PhotoDB.AnchorPosition.Center); 
    FullsizeImage.Dispose(); 

공지했다 .. 나는 .. 전에이 작업을 수행하지 않았고 그래서 GDI + 예외를 얻고 있었다

+3

참고 : Using 문을 사용해야합니다 (예 :'(Full FullizeImage = Image.FromFile (..)) {croppedImage = {}} '사용) .Dispose()를 수동으로 호출 할 필요가 없습니다. 이점은 더 깨끗한 코드이며, 무언가가 블록에서 예외를 던지더라도 여전히 폐기 될 것입니다. – gregmac