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 692727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:40:50+00:00 2026-05-14T02:40:50+00:00

This code works great for generating thumbnails, but when given a very large (100MB+)

  • 0

This code works great for generating thumbnails, but when given a very large (100MB+) TIFF file, it throws OutOfMemoryExceptions. When I do it manually in Paint.NET on the same machine, it works fine. How can I improve this code to stop throwing on very large files?

In this case I’m loading a 721MB TIF on a machine with 8GB RAM. The Task Manager shows 2GB used so something is preventing it from using all that memory. Specifically it throws when I load the Image to calculate the size of the original. What gives?

/// <summary>Creates a thumbnail of a given image.</summary>
/// <param name="inFile">Fully qualified path to file to create a thumbnail of</param>
/// <param name="outFile">Fully qualified path to created thumbnail</param>
/// <param name="x">Width of thumbnail</param>
/// <returns>flag; result = is success</returns>
public static bool CreateThumbnail(string inFile, string outFile, int x)
{
  // Mathematically determine Y dimension
  int y;
  using (Image img = Image.FromFile(inFile)) // Exception thrown
      y = (int)((double)img.Height * ((double)x / (double)img.Width));

  // Make thumbnail     
  using (Bitmap bmp = new Bitmap(inFile)) 
    using (Bitmap thumb = new Bitmap((Image)bmp, new Size(x, y))) 
      using (Graphics g = Graphics.FromImage(thumb)) {
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.InterpolationMode = InterpolationMode.High;
        g.CompositingQuality = CompositingQuality.HighQuality;
        ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders()[1];
        EncoderParameters ep2 = new EncoderParameters(1);
        ep2.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
        g.DrawImage(bmp, new Rectangle(0,0,thumb.Width, thumb.Height));
        try {
          thumb.Save(outFile, codec, ep2);
          return true; }
        catch { return false; }
      }
}
  • 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-14T02:40:50+00:00Added an answer on May 14, 2026 at 2:40 am

    My wild guess is that, you are running it as a 32-bit application. Which limits your app’s memory usage to a theoretical 2 GB, which is really more like 1.5 GB empirically.

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

Sidebar

Related Questions

i am trying to use this code: <%= File.ReadAllText(Server.MapPath(Members/newsletters/welcome.html))%> which works great but now
This code works, but i dont understand why. With DeferredLoadingEnabld = false, I would
This code works in a windows forms application (it shows the preview) but not
So I have the following code with works great for randomly generating position for
This code works fine in IE8/7 and Firefox... But in Google Chrome i got
I'm trying to change the value on a <textarea> element. This code works great
I'm trying to use python to sftp a file, and the code works great
This code works great: import zmq, json, time def main(): context = zmq.Context() subscriber
This is my code that works great: IPRepository rep = new IPRepository(); var Q
I have written some code that works great, but I don't understand why it

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.