Results 1 to 2 of 2

Thread: Speed Up Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Speed Up Help

    I found a class to help me build gif animation. However, some of the code takes a long time to exicute large images. In the code is suggest a "non-safe" method should be implimented to make it faster. I'm a VB coder and no nothing about c#.
    Can anyone help me make this faster.

    C# Code:
    1. /**
    2.          * Extracts image pixels into byte array "pixels"
    3.          */
    4.         protected void GetImagePixels()
    5.         {
    6.             int w = image.Width;
    7.             int h = image.Height;
    8.             //      int type = image.GetType().;
    9.             if ((w != width)
    10.                 || (h != height)
    11.                 )
    12.             {
    13.                 // create new image with right size/format
    14.                 Image temp =
    15.                     new Bitmap(width, height );
    16.                 Graphics g = Graphics.FromImage( temp );
    17.                 g.DrawImage(image, 0, 0);
    18.                 image = temp;
    19.                 g.Dispose();
    20.             }
    21.             /*
    22.                 ToDo:
    23.                 improve performance: use unsafe code
    24.             */
    25.             pixels = GetPixels(image);
    26.             return
    27.             pixels = new Byte [ 3 * image.Width * image.Height ];
    28.             int count = 0;
    29.             Bitmap tempBitmap = new Bitmap( image );
    30.             for (int th = 0; th < image.Height; th++)
    31.             {
    32.                 for (int tw = 0; tw < image.Width; tw++)
    33.                 {
    34.                     Color color = tempBitmap.GetPixel(tw, th);
    35.                     pixels[count] = color.R;
    36.                     count++;
    37.                     pixels[count] = color.G;
    38.                     count++;
    39.                     pixels[count] = color.B;
    40.                     count++;
    41.                 }
    42.             }
    Visual Studio .NET 2005/.NET Framework 2.0

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Speed Up Help

    Basically, its means using pointers to the image's pixels... Since I rarely work with graphics, CP has a submission and there's an ImageTraverser.cs class that has a GetPixel method which returns a color and the author claims is 75% faster than the .NET GetPixel method - which would speed up your class here immensely..

    http://www.codeproject.com/cs/media/ImageTraverser.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width