CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jun 2008
    Posts
    2,477

    Resolved How to convert a 32bppArgb image to Indexed?

    I have an image which is in the format of 32bppArgb. Now, this image is greyscale, so for every pixel, r = g = b, it is simply the brightness that varies. I would like to false color some of the pixels that are over-saturated (brightness > someConstant). I would like to use the Bitmap's Palette property, but to do so I need to have an indexed image.

    So, I try to convert my image to 8bppIndexed. The problem is that the conversion routine does not know that the image is in greyscale, so every pixel gets set to pure black (i.e., no color, so every pixel is converted to the same thing in 8-bit land).

    Does anyone know how to convert this image to 8bppIndexed without losing the brightness? I should note that I cannot loop through each pixel and check for myself. The user will be utilizing a TrackBar to change the overall intensity of the image. I cannot scan the entire image for every tick of the TrackBar, so a solution which uses the Palette property would be optimal.

    BTW, if you guys know a better way to do this that is just as good.

    EDIT:
    Solved this by using the ImageAttributes class:

    Code:
    List<ColorMap> maps = new List<ColorMap>();     
    
    for (int i = 30; i < 256; ++i)
    {
        ColorMap map = new ColorMap();
        map.OldColor = Color.FromArgb(255, i, i, i);
        map.NewColor = Color.FromArgb(i, Color.Red);
        maps.Add(map);
    }
    
    
    mAttrs.SetRemapTable(maps.ToArray());
    Last edited by BigEd781; February 23rd, 2009 at 07:21 PM.

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

Featured