Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1058547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:02:32+00:00 2026-05-16T18:02:32+00:00

When I rotate an image on my the server. It causes an out of

  • 0

When I rotate an image on my the server. It causes an out of memory exception.

    /// <summary>
    /// Rotates the specified img.
    /// </summary>
    /// <param name="img">The img.</param>
    /// <param name="rotationAngle">The rotation angle.</param>
    /// <returns></returns>
    public static Bitmap Rotate(Image img, float rotationAngle)
    {
        //create an empty Bitmap image
        Bitmap bmp = new Bitmap(img.Width, img.Height);

        //turn the Bitmap into a Graphics object
        using (Graphics gfx = Graphics.FromImage(bmp))
        {
            //now we set the rotation point to the center of our image
            gfx.TranslateTransform((float) bmp.Width/2, (float) bmp.Height/2);

            //now rotate the image
            gfx.RotateTransform(rotationAngle);

            gfx.TranslateTransform(-(float) bmp.Width/2, -(float) bmp.Height/2);

            //set the InterpolationMode to HighQualityBicubic so to ensure a high
            //quality image once it is transformed to the specified size
            gfx.SmoothingMode = SmoothingMode.HighQuality;
            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gfx.CompositingQuality = CompositingQuality.HighQuality;
            gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;

            //now draw our new image onto the graphics object
            gfx.DrawImage(img, new Point(0, 0));
        }

        //return the image
        return bmp;
    }

The exception is occurring on this line: gfx.DrawImage(img, new Point(0, 0));
I’ve search around the internet and found a number of people with a similar problem, but no solution.

Is there a solution? Or is there another library I can use besides the GDI+ to rotate my images? Maybe there is something in WPF?

Stacktrace:

[OutOfMemoryException: Out of memory.]
   System.Drawing.Graphics.CheckErrorStatus(Int32 status) +1588745
   System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y) +227
   System.Drawing.Graphics.DrawImage(Image image, Point point) +26
   Chucksoft.Core.Drawing.ImageResizer.Rotate(Image img, Single rotationAngle) in C:\Projects\ChucksoftCore\Branches\2.5.0\Source\Chucksoft.Core\Drawing\ImageResizer.cs:245
   Chucksoft.Core.Drawing.ImageResizer.Rotate(Byte[] b, Single angle, ImageFormat format) in C:\Projects\ChucksoftCore\Branches\2.5.0\Source\Chucksoft.Core\Drawing\ImageResizer.cs:22
   TheMemorableMoments.Domain.Services.ImageService.Rotate(IEnumerable`1 media, User user, Single angle) in C:\Projects\TheMemorableMoments\Branches\2.1.0\Source\TheMemorableMoments\Domain\Services\ImageService.cs:34
   TheMemorableMoments.Domain.Services.ImageService.RotateLeft(List`1 media, User user) in C:\Projects\TheMemorableMoments\Branches\2.1.0\Source\TheMemorableMoments\Domain\Services\ImageService.cs:69
   TheMemorableMoments.UI.Controllers.User.PhotosController.Rotate(IMediaFiles media, Action`2 resizeMethod) in C:\Projects\TheMemorableMoments\Branches\2.1.0\Source\TheMemorableMoments.UI\Controllers\User\PhotosController.cs:408
   TheMemorableMoments.UI.Controllers.User.PhotosController.RotateLeft(Media media) in C:\Projects\TheMemorableMoments\Branches\2.1.0\Source\TheMemorableMoments.UI\Controllers\User\PhotosController.cs:396
   lambda_method(Closure , ControllerBase , Object[] ) +127
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +258
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.&lt;&gt;c__DisplayClassd.&lt;InvokeActionMethodWithFilters&gt;b__a() +125
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709
   System.Web.Mvc.Controller.ExecuteCore() +162
   System.Web.Mvc.&lt;&gt;c__DisplayClass8.&lt;BeginProcessRequest&gt;b__4() +58
   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +20
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:02:33+00:00Added an answer on May 16, 2026 at 6:02 pm

    I got it working. I never figured out the “Out Of Memory” Exception. Instead I used the RotateFlip method hanging of the Image Class. Looking at the RotateFlip code, in Reflector, it’s a direct call into the Native Library. The drawback to this method, is you can only rotate in 90 degree increments. For me it’s works great.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.