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:
/** * Extracts image pixels into byte array "pixels" */ protected void GetImagePixels() { int w = image.Width; int h = image.Height; // int type = image.GetType().; if ((w != width) || (h != height) ) { // create new image with right size/format Image temp = new Bitmap(width, height ); Graphics g = Graphics.FromImage( temp ); g.DrawImage(image, 0, 0); image = temp; g.Dispose(); } /* ToDo: improve performance: use unsafe code */ pixels = GetPixels(image); return pixels = new Byte [ 3 * image.Width * image.Height ]; int count = 0; Bitmap tempBitmap = new Bitmap( image ); for (int th = 0; th < image.Height; th++) { for (int tw = 0; tw < image.Width; tw++) { Color color = tempBitmap.GetPixel(tw, th); pixels[count] = color.R; count++; pixels[count] = color.G; count++; pixels[count] = color.B; count++; } }




Reply With Quote