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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:44:06+00:00 2026-05-22T14:44:06+00:00

Hi: IN my application,I have some images saved in the db,so I create a

  • 0

Hi:
IN my application,I have some images saved in the db,so I create a ImgDownLoad.aspx to retrive the image and retun them,since the image in the db may very large(some of them is more than 20M),so I generate some thumbnails ,this is the code:

page_load(){
  string id=Requset.QueryString["id"];
  string imgtype=Requset.Querystring["itype"];

  if(imgType=="small")
  {
   //request the thumbnail
    string small_loaction=getSmallLocationById(id);

    if(!File.exists(small_location)
    {
      byte[] img_stream =getStreamFromDb(id);
      Image img=Image.frameStream(new MemsorStream(img_steam));//here,I often get the out of memory error,but I am not sure when it will happen.
      generateSmallImage(img,location)
    }
   Response.TransferFile(small_location);
  }

  else if(imgType=="large"){
    byte[] img_stream =getStreamFromDb(id);
    new MemorySteam(img_stream).writeTo(Response.outputstream);
  } 
}

Anything wrong?

ALso,since I do not know the image format,so I can not add the

Response.contenttype="image/xxx";

What confusing me most is that I will meet the out of memory error,so I change the code:

try{
          byte[] img_stream =getStreamFromDb(id);
          Image img=Image.frameStream(new MemsorStream(img_steam));//here,I often get the out of memory error,but I am not sure when it will happen.
          generateSmallImage(img,location)
}
catche(exceptin e){
 //the small image can not generated,just return the whole image
  new MemorySteam(img_stream).writeTo(Response.outputstream);
  return;
}

In this case,I will avoid the out of memory problem,but some large image can not downloaded sometime.

So I wonder if there are any ways to handle the large image stream?

Take a large image for exmaple:

resolution:12590x4000
size:26M.

In fact,I have opened a large image(almost 24M) with the mspaint,and then save the image again,I found that it size is much smaller than at first. So is it possible to resize the image in the server side? Or other good manners to hanle my problem?

  • 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-22T14:44:07+00:00Added an answer on May 22, 2026 at 2:44 pm

    Firstly, you’re not disposing of the Image and Stream type instances that you create – given subsequent calls, over time, this is bound to cause issues; particularly with images around the 20meg mark!

    Also, why create the thumbnails every call? Create once and cache, or flush to disk: either way, serve a ‘one you made earlier’ rather than do this processing over and over.

    I would recommend, however, you try an minimise the size (in bytes) of the images. Some might argue that they shouldn’t be in the database if over 1meg, but store them on disk and a file name in the database. I guess that’s open for debate, browse if interested.

    To your comment, I’d urge you not to allow other scopes take control of resources ‘owned’ by another; dispose of items in the scope that creates them (obviously sometimes some things need to stick around, but what is responsible for them should be clear). Here’s a little rework of some of your code:

    if (imgType == "small")
    {
        string small_loaction = getSmallLocationById(id);
        if(!File.exists(small_location)
        {
            byte[] imageBytes = getStreamFromDb(id);
            using (var imageStream = new MemoryStream(imageBytes))
            {
                using (var image = Image.FromStream(imageStream)) 
                {
                    generateSmallImage(image, small_location)
                }
            }         
        }
        Response.TransferFile(small_location);
    }
    else if (imgType=="large")
    {
        byte[] imageBytes = getStreamFromDb(id);
        Response.OutputStream.Write(imageBytes, 0, imageBytes.Length);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a play application and have some models. One of them contains
In my WP7 application I have downloaded 200 images from Web and saved in
I have a method in my application which retrieves the last saved image in
In my WPF application I have some drawing functionality. I have solved this using
In my Java application I have some copy-constructors like this public MyClass(MyClass src) {
I have a VC++ application and in my application i have some basic file
In my application I have some link buttons there but when I right click
I am developing a Java Desktop Application but have some confusions in choosing a
I am devloping smart device application in C#. In this application I have some
I have console application. In that i have some process that fetch the data

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.