Thema: Delphi Farbwert zu Dezimal

Einzelnen Beitrag anzeigen

Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.754 Beiträge
 
Delphi 10.4 Sydney
 
#26

AW: Farbwert zu Dezimal

  Alt 29. Mär 2019, 07:50
.. ein Versuch:
Delphi-Quellcode:
var
  imgSpectrum: Array[0..9,0..9] of Integer;
  h,w: Integer;
  x, dx ,y, dy: Integer;
  c,d,red,green,blue: Integer;
  alpha: Integer;

  fade: Integer;
  mEffect: Byte;
begin
  try
    h := 9;
    w := 9;
    case mEffect of
      0: begin
           d := fade * 255;
           for y:= 0 to h do
             for x := 0 to w do
               begin
                 alpha := ((imgSpectrum[x,y] and $FF000000) shr 24) and $FF;
                 alpha := alpha - d;
                 if alpha < 0 then
                   alpha := 0;
                 c := imgSpectrum[x,y] and $FFFFFF;
                 if alpha > 127 then
                   imgSpectrum[x,y] := c or ((alpha -256) shl 24)
                 else
                   imgSpectrum[x,y] := c or (alpha shl 24);
               end;
         end;
      1: begin
            d:= fade * 10;
            for y := 0 to h do
              for x := 0 to w do
                begin
                  if (x > 0) and (y > 0) and (x < (w-1)) and (y < (h -1))then
                    begin
                      red := 0;
                      green := 0;
                      blue := 0;
                      alpha := 0;
                      for dy := -1 to 1 do
                        for dx := -1 to 1 do
                          begin
                            c := imgSpectrum[x+dx,y+dy];
                            alpha := (((c and $FF000000) shr 24) and $FF) + cardinal(alpha);

                            red := red + ((c and $FF0000) shr 16);
                            green := green + (( c and $FF00) shr 8);
                            blue := blue + (c and $FF);
                          end;
                      red := red div 9;
                      green := green div 9;
                      blue := blue div 9;
                      alpha := (alpha div 9) - d
                      if alpha < 0 then
                        alpha := 0;
                      c := blue or ( green shl 8) or (red shl 16);
                      if alpha > 127 then
                        imgSpectrum[x,y] := c or ((alpha -256) shl 24)
                      else
                        imgSpectrum[x,y] := c or (alpha shl 24); end;
                end;

         end;
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
Grüße
Klaus
Klaus

Geändert von Klaus01 (29. Mär 2019 um 09:35 Uhr)
  Mit Zitat antworten Zitat