How to draw an image very fast from a file in the stream format?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mina2040
    New Member
    • Dec 2008
    • 6

    How to draw an image very fast from a file in the stream format?

    Hi there,

    I would like to display thousands of image files on the screen. I am using the following code to display them:

    Bitmap Origbmp = new Bitmap(Filename );
    bmp = new Bitmap(Origbmp. Width, Origbmp.Height, PixelFormat.For mat32bppArgb);
    Graphics gr = Graphics.FromIm age(bmp);
    gr.DrawImage(Or igbmp, 0, 0, Origbmp.Width, Origbmp.Height) ;


    but now the files are in a special format that cannot be displayed using the above code. So I have to load the file into memory, change some particular bytes and then pass them to the Origbmp. so I do as follows:

    //read the file into a stream
    byte[] fileInBytes = File.ReadAllByt es(Filename);
    Stream fileInStream = new MemoryStream(fi leInBytes);
    fileInStream.Wr ite(Newbytes, pos,len);
    Bitmap Origbmp = new Bitmap(fileInSt ream);
    bmp = new Bitmap(Origbmp. Width, Origbmp.Height, PixelFormat.For mat32bppArgb);
    Graphics gr = Graphics.FromIm age(bmp);
    gr.DrawImage(Or igbmp, 0, 0, Origbmp.Width, Origbmp.Height) ;

    is there anyway to do it faster? How can I read the file directly to a stream rather than first reading it to a byte array and then to a stream?
    Is there any other way to do the whole thing more efficient and faster?
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    If the intention is to modify pixels on the bitmap before it's drawn, wouldn't you be better using the Graphics library?

    Aimee.

    Comment

    • mina2040
      New Member
      • Dec 2008
      • 6

      #3
      Hi Aimee,

      thanks for your post. The intention is to modify some buyes of the file before drawing it on the screen. Has this make it more clear?

      Comment

      • mzmishra
        Recognized Expert Contributor
        • Aug 2007
        • 390

        #4
        I did something like below in my code to display image in a webpage.

        byte[] bArrImage = null;
        MemoryStream memoryStream = null;
        System.Drawing. Image Image = null;
        bArrImage = //code to get the image from database
        memoryStream = new MemoryStream(bA rrImage);
        Image = Bitmap.FromStre am(memoryStream );

        Comment

        Working...