Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

.NET Bitmaps

Back to Forum: Tech Off
  • User profile image

    OK, I hope I'm missing something here, because I'm slightly stuck. 

    Here's what I'm doing.  I load a .GIF as an embedded resource in a .NET DLL, into a Bitmap object.  I create a new Bitmap object, and copy the original image into the larger image.  However, the orignal image isn't copied exactly.  It looks like Graphics.DrawImage is doing some kind of anti-aliasing or something.  The colors are smoothed together.

    A more detailed analysis:

    1) I load up the .GIF file into a 8bppIndexed Bitmap.  Let's call this ImageA.  ImageA includes a yellow-and-white checkered pattern.

    2) I create a new 32bpp Bitmap, ImageB.

    3) I get the Graphics from ImageB, and call DrawImage, passing in ImageA.

    4) I do some other stuff to ImageB, like use DrawText to draw in some user-input.

    5) Now, I need to serve up ImageB as a .GIF, so I create a new 8bppIndexed Bitmap (ImageC), and manually copy the bits out of ImageB (constructing the palette as I go).

    6) Since I know that ImageA is only 16 colors, and the text is monochrome, everything should fit in ImageC's 256 palette.  But ImageB has something like 300 colors, so ImageC's palette gets mangled.

    7) When I view ImageC in IE, I can see that the checker pattern is smoothed over.  I'm pretty sure that DrawImage is doing this.

    a) how do I stop Graphics.DrawImage from doing this, or
    b) what other method can I use to copy in ImageA without this anti-aliasing?

    I could write a subroutine that copies the bits manually, but it just seems rediculous that this is happening to begin with.

  • User profile image

    Try using DrawImageUnscaled.

  • User profile image

    Hey, you rock!  That worked!  By the documentation, I had figured that DrawImageUnscaled only effected the size / dpi of the image, not the colors.  Thanks!!

    ... I just figured out what I was doing wrong.  The DrawImageUnscaled(image, x, y, width, height) documentation says that a call to it is the same as DrawImage(image, x, y).  It suddenly dawned on me, I had noticed earlier that there was a const for the width / height of ImageA that was wrong, but I figured that it would just effect the placement and size of ImageA in ImageB in my code.  I hadn't figured on it messing with the colors as well.

    Again, thanks a bunch!  I was bound to be scratching my head for days.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.