Three Image Problems  
Author Message

PostPosted: Visual C# General, Three Image Problems Top

I'm working with generating an image through a class and sending it from a server to a client. The original image is 1024 by 768 pixels, with 32-bit colors.

  1. How can I change an image's pixel format The Image class has a read-only PixelFormat property. I need to be able to change my image from 32-bit colors to 24, 16, and 8 bits. Going through each pixel individually using the Bitmap GetPixel and SetPixel functions is too slow (takes perhaps 30 seconds per image).
  2. I want to compare two images to detect differences in their pixels. Simply, whether two pixels in the same position are different colors. How can I do that quickly The Image class has no pixel accessors (as far as I know) and the Bitmap class has GetPixel and SetPixel, but those are too slow.
  3. Are there problems I should keep in mind about saving an image into a format I'm having a problem with opening bitmaps, changing their dimensions, and saving them as JPEGs. The resulting image is broken into several squares with each square gardbled to the point of being useless. I know that's not what's supposed to be happening because when I save the images as JPEGs in Paint it works just fine. Here is the code:
preImage = Image.FromFile("C:\image.bmp");
finalWidth = preImage.Width;
finalHeight = preImage.Height;
postImage = preImage.GetThumbnailImage(finalWidth, finalHeight, new Image.GetThumbnailImageAbort(ImageAbort), IntPtr.Zero);
postImage.Save(buffer, ImageFormat.Bmp );

Notice that the code does not actually change anything about the image. I modified it to verify that the problem isn't related to the JPEG formatting itself. It still happens when I use the Bitmap format, and even when I get a thumbnail of the same size as the original image. It also happens if the thumbnail is smaller.

Visual C#17