Einzelnen Beitrag anzeigen

hboy

Registriert seit: 16. Jan 2004
364 Beiträge
 
#5

AW: Farben nach RGB unrechnen?

  Alt 15. Jan 2011, 10:53
Delphi-Quellcode:
type TRGBColor = packed record
  case Integer of
    1 : (col: Cardinal);
    2 : (chans: Array[0..3] of byte);
end;

function AsRGB(color: TColor; DC: HDC = 0): TRGBColor;
var
  rgbc: TRGBColor absolute color;
  entry: PALETTEENTRY;
const
  cpSystemPalette = $00;
  cpActingPalette = $01;
  cpLogicalPalette = $02;
  cpGenericPalette = $08;
  cpNoColor = $1F;
  cpDefaultColor = $20;
  cpSystemColor = $FF;
begin
  case rgbc.chans[3] of
    cpGenericPalette, cpLogicalPalette:
      begin
        result.col := (rgbc.col and $00FFFFFF);
      end;

    cpNoColor, cpDefaultColor :
      begin
        result.col := rgbc.col;
      end;

    cpActingPalette :
      begin
        if (GetDeviceCaps(DC,RASTERCAPS) and RC_PALETTE) <> 0 then
        begin
          if 1 = GetPaletteEntries( GetCurrentObject(DC, OBJ_PAL),
                                    rgbc.chans[0], 1, entry) then
          begin
            result.col := $00000000;
            result.chans[0] := entry.peRed;
            result.chans[1] := entry.peGreen;
            result.chans[2] := entry.peBlue;
          end;
        end
        else
          result.col := PaletteIndex(rgbc.chans[0]);
      end;

    cpSystemPalette :
      begin
        result.col := PaletteIndex(rgbc.chans[0]);
      end;

    cpSystemColor :
      begin
        result.col := GetSysColor(rgbc.chans[0]);
      end;

  end;
end;
Soweit ohne Gewähr. Bitte vervollständigen
Power is nothing without TControl

Geändert von hboy (15. Jan 2011 um 11:45 Uhr) Grund: iterativ von Fehlern befreit ;-)
  Mit Zitat antworten Zitat