Solution for Error: 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+.
Cause of Error: Trying to access invalid path or Trying to save image for path that doesn't exist.
Example: I was trying to perform following
imgThumbnailImage = imgOriginalImage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
imgThumbnailImage.Save(Server.MapPath(thumbnailImagePath), System.Drawing.Imaging.ImageFormat.Jpeg);
Wherein thumbnailImagePath will defer when you are trying to perform operation in sub directories.
i.e. Directory Structure.
Web Application Root
|----- ImageFolder
|----- UserWork Folder
|------ Tried to access ImageFolder which was in Root directory
Solution of Error: Try to access right directory path for image. Now following path points to root directory where actual image exist.
imgThumbnailImage = imgOriginalImage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
imgThumbnailImage.Save(Server.MapPath("..\\" + thumbnailImagePath), System.Drawing.Imaging.ImageFormat.Jpeg);
No comments:
Post a Comment