TBitmap color "Search and Replace" lazarus / 39-Graphics ---------------------------------------------------------------------- ArminLinder · 2017-02-14 20:33 Hi all, is there a fast way to replace a color with a different color in a TBitmap, keeping the alpha value unchanged? What I have is a bunch ob BitBtn buttons on form, each having the usual  bitmaps for the different button states. Works well. Currently I have drawn glyphs in shades of black and grey, which fits Windows 7. On Windows 10 it looks alien, because Windows 10 uses blue color tones. The idea is to replace the black shades with blue shades in FormCreate, so I do not have to maintain two different sets of bitmaps. I found some code samples which look promising, but haven't got the time to do a lengthy trial session tonight, need a quick solution, so a working code snipped for this would be great. Thnx Armin. ---------------------------------------------------------------------- derek.john.evans · 2017-02-14 21:51 Unsure of your exact needs but, its easy to iterate the pixels of a bitmap via rawimage. Here is some code to offset the hue: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses GraphUtil, Math;procedure BitmapOffsetHue(A: TBitmap; AOffset: integer);var  LHue, LLit, LSat: byte;  LPix, LEnd: PByte;begin  Assert(A.PixelFormat = pf32bit);  A.BeginUpdate;  try    LPix := A.RawImage.Data;    LEnd := LPix + A.RawImage.DataSize - 4;    while LPix <= LEnd do begin      RGBtoHLS(LPix[2], LPix[1], LPix[0], LHue, LLit, LSat);      LHue := EnsureRange(LHue + AOffset, 0, 255);      HLStoRGB(LHue, LLit, LSat, LPix[2], LPix[1], LPix[0]);      Inc(LPix, 4);    end;  finally    A.EndUpdate;  end;end; If you have grayscale images you can assign a hue and lightness to colorize. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure BitmapColourize(A: TBitmap);var  LHue, LLit, LSat: byte;  LPix, LEnd: PByte;begin  Assert(A.PixelFormat = pf32bit);  A.BeginUpdate;  try    LPix := A.RawImage.Data;    LEnd := LPix + A.RawImage.DataSize - 4;  while LPix <= LEnd do begin      RGBtoHLS(LPix[2], LPix[1], LPix[0], LHue, LLit, LSat);      LHue := 140;      LSat := 128;      HLStoRGB(LHue, LLit, LSat, LPix[2], LPix[1], LPix[0]);      Inc(LPix, 4);    end;  finally    A.EndUpdate;  end;end;  Sometimes I like to load up a paint package to test out what color effect im looking for, and then try to code up a duplicate effect. Edit: Small bug fix. You should subtract the pixel size from LEnd just in case. ---------------------------------------------------------------------- ArminLinder · 2017-02-15 06:39 Hi ... looks promising. thank you! Armin.