locked
degrading the Performance memorystram writing RRS feed

  • Question

  • User911209228 posted

    HI,

     I have asp.net application. In my application , trying to write a bitmap image text into memorystream. But it is writing the text very slowly. How can I improve the performance.The below line of code used for ,

    for(int k=0; k<25; K++)

    {

    System.Drawing.Bitmap bmpMap = null;

    using (System.IO.MemoryStream stream = new System.IO.MemoryStream())

    {

    bmpMap.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);

    bmpMap.Dispose();

    Response.Clear();

    Response.ClearHeaders();

    Response.ContentType = "image/gif";

    stream.WriteTo(Response.OutputStream);// If I commentout it is loading fast

    stream.Dispose();

    stream.Close();

    Response.End();

    }

    }

    The above  block of code, if I have commented out  the stream.WriteTo(Response.OutputStream) , then it is loading very fast. How we can write the bitmap image text to memorystream very fastly

    Thanks,

    Dileep

    Wednesday, June 20, 2018 7:19 AM

All replies

  • User753101303 posted

    Hi,

    It is when sending to the browser so the network is likely the llimit here. What is the size of your image ? It seems to be in a loop which is weird or the loop is done before to process images ???

    Wednesday, June 20, 2018 7:29 AM
  • User911209228 posted

    BMP height and width is 75px. Every time my image text will change, thts why put the logic inside loop.

    Wednesday, June 20, 2018 9:25 AM
  • User753101303 posted

    75x75 seems fine. What is the actual size in KB ? This is a multi frame GIF ?

    I still don't see the purpose of this loop as you should send back a single image file ? I suspect that for now it's rather some kind of logic programming issue that might cause maybe exceptions and slow down your code rather than really a problem with raw performance.

    Wednesday, June 20, 2018 9:36 AM
  • User911209228 posted

    why we are using loop is , we are using 20 different image text, not  the same on every time. bmp image sixe text is less than a kb.

    Wednesday, June 20, 2018 10:06 AM
  • User753101303 posted

    I still don't get it. For now it seems you have your response block inside a loop which doesn't seems something that should work moreover with Response.End(); When an http query is done you are usually expected to send back a single response. Sending less than a Kb to a browser shouldn't be a problem. 

    I suspect the problem is not where you think. Either it is actually bigger than what you think or the loop is causing issues (working the first time and generating excepting for the other iterations).

    What if you try for(int k=0; k<1; k++) // Typo on K++ ?

    You are sending back multiple images and expect to see them in close succession in the page that asked for them ??? If this is an animation you should rather write each frame to the same animated gif file and then send back this file.

    Wednesday, June 20, 2018 11:23 AM
  • User911209228 posted

    This is not related with a size or loop iteration problem. I am able to write image text suceesfuly , but is very slowly one by one.

    The line of code stream.WriteTo(Response.OutputStream); only taking time for each iteration. and supposed to comment out this line code, then no time delay , but no text is writing.

    it is typo error in previous post, now the loop changed to (int k=0; k<10; k++)

    You are sending back multiple images and expect to see them in close succession in the page that asked for them ??? YES

    There is no animation is used in the gif image.

    sending multiple images  thorough the loop.

    Wednesday, June 20, 2018 12:53 PM
  • User753101303 posted

    I don't see how it could work. You are expected to send a single response for each http request and it seems you are calling Response.End() inside this loop. If you want to show an animation you should send a single gif image with multiple frames rather than trying to send multiple images in close succession (or request each image in turn from the client side).

    I suspect that an exception happens for all expect the first iteration and that the time you see is spent in processing those exceptions rather than in sending actual content. Have you tried to check the Windows application log to see if exception messages are written there?

    Wednesday, June 20, 2018 1:05 PM