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

  • SEARCH
  • Home
  • 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 355759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:02:52+00:00 2026-05-12T12:02:52+00:00

It look desceptively easy to use System.Drawing to create thumbnails in your ASP.NET application.

  • 0

It look desceptively easy to use System.Drawing to create thumbnails in your ASP.NET application. But MSDN tells you:

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

I’m seeing intermittented ‘out of memory’ errors within this type of GDI+ code. I’m beginning to suspect this is the cause.

How ARE people doing server side image manipulation? Can anyone recommend any alternative that WON’T blow up my server?

The relevant code below. The exception intermittently happens in System.Drawing.Graphics.DrawImage. I’ve just inherited this project, so I’d need to check the logs to see how often this is being hit / how often we get an exception…

public byte[] Resize(int newWidth, int newHeight, Image orignalImage)
{
    Bitmap bitmap = new Bitmap(newWidth, newHeight);
    Graphics g = Graphics.FromImage(bitmap);
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

    Rectangle r = new Rectangle(0, 0, newWidth, newHeight);
    g.DrawImage(orignalImage, r, r.X, r.Y, orignalImage.Width, orignalImage.Height, GraphicsUnit.Pixel);

    MemoryStream stream = new MemoryStream();
    bitmap.Save(stream, ImageFormat.Jpeg);

    // clean up memory leaks
    if (bitmap != null)
    {
        bitmap.Dispose();
        bitmap = null;
    }
    if (g != null)
    {
        g.Dispose();
        g = null;
    }


    return stream.ToArray();
}

UPDATE: I’ve searched thru the whole project for anywhere we are using GDI+ and put using() { } around everything that’s IDisposable. I haven’t seen one ‘out of memory’ exception since I did this.

  • 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-12T12:02:52+00:00Added an answer on May 12, 2026 at 12:02 pm

    Assuming you will be doing “stuff” per request, the issues might be

    1. Processor intensive operation: manipulation of images, which could take time.

    2. In case you are saving the file, it will lead to disk issues.

    3. You can consider using HTTP handlers,

    4. Disposing System.Drawing objects should be a priority(using(){} statement )

    5. Asynchronous Pages can be explored here.

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

Sidebar

Related Questions

Delegates look like such a powerful language feature, but I've yet to find an
Look at your Gmail inbox. You have 3 main columns contains the Sender contains
Look at the following example (partially taken from MSDN Blog ): class Animal {
Look, I know we should move on and install the newest php already. But
Look here (Abstract Class Design): http://msdn.microsoft.com/en-us/library/ms229047.aspx It says: (1) Do not define public or
Look at this code: DELIMITER $$ DROP TRIGGER IF EXISTS `after_product_insert` $$ CREATE TRIGGER
look at this please http://jsfiddle.net/xhpqa/4/ the sub_menu div keeps hiding if mouseover it because
Look at the following code: window.onload = someFunction; Many times I see the use
Look at this image: alt text http://img139.imageshack.us/img139/4488/picture2ep3.png I know how to add UITableView with
Look at this situation: www.websitea.com displays an img tag with a src attribute of

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.