I store in an image in a RES file. Because it is so large, I first convert it from a BMP to a JPG. Then I load the JPG from the RES file, convert it to a BMP, and can now manipulate the image on a pixel by pixel basis. I want to convert all the "White" pixels to cllMyLightBlue.

It's easy to change one color in a BMP into another color:

IF   Bitmap.Canvas.Pixels[i,j] = clWhite
        THEN Bitmap.Canvas.Pixels[i,j] := clMyLightBlue

The problem is - in the process of converting from BMP to JPG back to BMP, some "bleeding" of colors, near the edges, has occurred. While the white areas of the image look basically white, they are not exactly. This approach works pretty well:

delta := 100000;                  // determine by trial and error
   IF   (Bitmap.Canvas.Pixels[i,j] > (clWhite-delta)) and
    F   (Bitmap.Canvas.Pixels[i,j] < (clWhite-delta)) then
        THEN Bitmap.Canvas.Pixels[i,j] := clMyLightBlue

Since the pixel "number" is an amalgam of RGB numbers, it seems that a better approach would be to change the pixel color only if all 3 RGB values were within some tolerance level...perhaps a delta of 10.

How can I test, and replace, specific RGB vlues of a pixel? Is there a better way to clean up my image.

10 Years
Discussion Span
Last Post by bob on whidbey

I too was surprised at how well my kludgy approach seemed to work. Thanks for pointing out efg's tech note.

Since "white" has 255 in all RGB bits I don't have to test for something higher than than. The following code workes very well when I set 'maxd' to 255-50.

with Row do
if (rgbtRed > maxd) and (rgbtGreen > maxd) and (rgbtBlue > maxd) then
Row :=LightBlueBits;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.