Change the HUE of the bitmap, but keep the background color?

I experimented with an example Change HUE/Saturationfound on the EFG website: http://www.efg2.com/Lab/Library/Delphi/Graphics/Color.htm

enter image description here

I want to use the methods found in this example to change the color values โ€‹โ€‹of some bitmaps (which will be used in TImage). There is one problem that I encountered, and this is with TImages, which have transparent bitmaps; I do not want the background color to change its HUE, but rather the actual image data.

Take this model image that we can work with (although you can use any image with transparency):

enter image description here

  • Download the daemon Change HUE/Saturationfrom the link above.
  • Now load the button image above into ImageOriginal.
  • Set Delta Saturation to 1.
  • Run the project.

Some output results:

enter image description hereenter image description here

What I would like to do here is to keep the original background color (defined by the lower left most pixels) and adjust only the hue for the rest of the image. Thus, the output results will look like this (edited in Paint.NET):

enter image description hereenter image description here

Let me use another sample image for testing that contains more image data:

enter image description here

As before, with the first image sample, the results may be something like this:

enter image description hereenter image description here

When the desired results should be as follows:

enter image description hereenter image description here

, HUE , , , , X . ( ).

, ( ), :

<411 >

HUE :

enter image description here

:

enter image description here

, HUE , , - EFG . , , HUE, , .

HUE ?

+5
2

, , , /. , , :

PROCEDURE TFormChangeHS.UpdateBitmap;
    ..
    S              :  TReal;
    V              :  TReal;

    FixColor: TRGBTriple;                            // New variable
BEGIN
  DeltaSaturation := SpinEditDeltaSaturation.Value;
  NewHue := TrackBarHue.Position;

  Bitmap := TBitmap.Create;
  TRY
    Bitmap.Width  := ImageOriginal.Width;
    Bitmap.Height := ImageOriginal.Height;
    Bitmap.PixelFormat := ImageOriginal.Picture.Bitmap.PixelFormat;
    ASSERT(Bitmap.PixelFormat = pf24bit);

    // save bottom left color
    FixColor := PRGBTripleArray(
                  ImageOriginal.Picture.Bitmap.ScanLine[Bitmap.Height - 1])^[0];
    //--

    FOR j := 0 TO Bitmap.Height-1 DO
    BEGIN
      RowIn  := ImageOriginal.Picture.Bitmap.Scanline[j];
      RowOut := Bitmap.Scanline[j];
      FOR i := 0 TO Bitmap.Width-1 DO
      BEGIN
        WITH RowIn[i] DO
        BEGIN

          // copy the color to target and continue with next iteration
          if (RowIn[i].rgbtBlue = FixColor.rgbtBlue) and
              (RowIn[i].rgbtGreen = FixColor.rgbtGreen) and
              (RowIn[i].rgbtRed = FixColor.rgbtRed) then begin
            RowOut[i] := FixColor;
            Continue;
          end;
          //--

          // convert pixel coordinates to HSV
          RGBtoHSV(rgbtRed, rgbtGreen, rgbtBlue, H, S, V);
        END;
        ..
        ..


:

enter code here

+5

, :

-, , ... (, , delphi,...)

, , ...

... ...

...

+2

All Articles