Home > Software design >  Apply color filter to a bitmap
Apply color filter to a bitmap

Time:05-06

I would need to color an image as in the example below. I would need to apply this transformation in memory, after loading the image from a file.

An example of what I would like to achieve can be found at the following enter image description here

The color of the filter must be customizable. I also have the ImageEn libraries available from which I started to do some tests, using the CastColorRange function, which however does not give me the expected result

var
  FIMageEn: TImageEn;
...

procedure TTest.ApplyColorMask(const ARGBFilter: TRGB);
begin
  FIMageEn.Proc.CastColorRange(FProcOverrideColorStartRange, // BeginColor
    FProcOverrideColorEndRange, // EndColor
    ARGBFilter); // Filter
end;

The problem with the piece of code shown above is that the function requires a range of colors in rgb format, but since the images are all different from each other, I don't know what range to set

CodePudding user response:

You don't need a third-party library for this.

It looks like the desired transformation is to set the per-pixel hue (H) to a fixed value, preserving saturation (S) and value (V in the HSV colour model).

So, you merely need some RGB<->HSV conversion functions. Personally, I use Screenshot

Screen recording

  • Related