Einzelnen Beitrag anzeigen

David Martens

Registriert seit: 29. Sep 2003
205 Beiträge
 
Delphi XE Enterprise
 
#27

AW: PNG zur Laufzeit in ImageList einfügen

  Alt 11. Feb 2011, 11:21
Es geht

So um nur noch mein Ergebnis zu präsentieren:

1. Mit TImageList hat es NICHT geklappt. Was wohl auch an mir liegt. Ich hatte vergessen zu sagen das Bild selbst hat unterschiedliche Transparenz ich will das Bild nicht mit eine Gesamttransparenz zeichnen.

Hier der Code mit dem es geht und unten dann die Erklärung dazu:
Delphi-Quellcode:
      if Image <> nil then
      begin
        if Color <> clNone then
        begin
          Image2 := TPngImage.CreateBlank(COLOR_GRAYSCALE, 1, 16, 16);

          Image2.Canvas.Brush.Style := bsClear;

          Image2.Canvas.Font. Name := 'Small Fonts';
          Image2.Canvas.Font. Size := 5;
          Image2.Canvas.Font. Color := clWhite;

          Image2.Canvas.TextFlags := Image2.Canvas.TextFlags or ETO_OPAQUE;
          Image2.Canvas.TextOut(16 - Image2.Canvas.TextWidth(Text), - 2, Text);
        end;
      end;

      with Image do
      begin
        for y := 0 to Height - 1 do
        begin
          pb := AlphaScanline[y];
          for x := 0 to Width - 1 do
          begin
            ColorRGBToHLS(ImageColor, NewHue, NewLuminance, NewSaturation);

            if Image2.Pixels[x, y] = clWhite then
            begin
              Pixels[x, y] := clBlack;
              pb^[x] := 255;
            end
            else
              Pixels[x, y] := ColorHLSToRGB(NewHue, Trunc((pb^[x] + NewLuminance) / 2), NewSaturation);
          end;
        end;
      end;

      if Image <> nil then
      begin
        Liste.AddPng(Image);
      end;
1. TPngImage.CreateBlank(COLOR_GRAYSCALE, 1, 16, 16); erzeugt ein SCHWARZES Bild, ergo muß ich Weiß als Textfarbe nehmen.
2.
Delphi-Quellcode:
            if Image2.Pixels[x, y] = clWhite then
            begin
              Pixels[x, y] := clBlack;
              pb^[x] := 255;
            end
Das ist der eigentliche Knackpunkt, hier muß ich den Alphachannel auch noch setzen.

Vielen Dank an alle
David
  Mit Zitat antworten Zitat