Autor Beitrag
Rool
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 211



BeitragVerfasst: So 13.05.07 20:25 
Ich krieg es einfach nicht hin, mein erzeugtes Bitmap32 (Graphics32-Lib) als png zu speichern, habe mir die pngdelphi-lib runtergeladen, ein png in das bitmap32 zu laden (direkt oder über pngdelphi) ist kein problem aber ich kann mein semitransparentes bitmap32 nicht als png speichern. das kann doch eigentlich nicht sooo schwer sein.
kann mir da jemand helfen? wär super,

_________________
MFG Rool
uko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: Mo 14.05.07 08:24 
Hilft Dir das weiter:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
procedure TForm1.Save(const AFileName: String);
var
  imgPng: TPngObject;
  PixelPtr: PColor32;
  AlphaPtr: PByte;
  X, Y: Integer;
begin
  imgPng := TPngObject.Create;
  try
    // Bitmap32 in PNG laden
    imgPng.AssignHandle(FBitmap32.BitmapHandle, False, 0);

    // Ggf. Alpha-Kanal von Bitmap32 nach PNG uebertragen
    if FBitmap32.HasAlpha then
    begin
      imgPng.CreateAlpha;
      PixelPtr := PColor32(@FBitmap32.Bits[0]);
      for Y := 0 to FBitmap32.Height - 1 do
      begin
        AlphaPtr := PByte(imgPng.AlphaScanline[Y]);
        for X := 0 to FBitmap32.Width - 1 do
        begin
          AlphaPtr^ := PixelPtr^ shr 24;
          Inc(PixelPtr);
          Inc(AlphaPtr);
        end;
      end;
    end;

    // PNG-Datei speichern
    imgPng.SaveToFile(AFileName);
  finally
    imgPng.Free;
  end;
end;


Das Property HasAlpha von FBitMap32 ist eine eigene Erweiterung: Beim Einlesen in das BitMap32 merk ich mir, ob das Bild einen Alpha Channel hat:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
procedure TForm1.Load(const AFileName: String);
var
  pictImage: TPicture;
begin
  pictImage := TPicture.Create;
  try
    // Image laden
    pictImage.LoadFromFile(AFileName);

    // Image in Bitmap32 laden
    FBitmap32.Clear;
    FBitmap32.Assign(pictImage);

    // DrawMode zuruecksetzen
    FBitmap32.DrawMode := dmOpaque;
    FBitmap32.OuterColor := clNone;
    FBitmap32.HasAlpha := False;

    // DrawMode abhaengig von Image-Format und Transparenz/Alpha setzen
    if (pictImage.Graphic is TGraphicExGraphic) then
      with TGraphicExGraphic(pictImage.Graphic) do
      begin
        if ImageProperties.HasAlpha then
        begin
          FBitmap32.HasAlpha := True;
          FBitmap32.DrawMode := dmBlend;
        end
        else
        begin
          FBitmap32.DrawMode := dmTransparent;
          if (pictImage.Graphic is TPNGGraphic) then
            with TPNGGraphic(pictImage.Graphic) do
              FBitmap32.OuterColor := Color32(TransparentColor);
        end;

        if (pictImage.Graphic is TGIFGraphic) then
          with TGIFGraphic(pictImage.Graphic) do
            if Transparent then
            begin
              FBitmap32.DrawMode := dmBlend;
              FBitmap32.OuterColor := TGIFGraphic(pictImage.Graphic).TransparentColor;
            end;
      end;
  finally
    pictImage.Free;
  end;
end;


und

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
TMyBitmap32 = class(TBitmap32)
  private
    FHasAlpha: Boolean;
  public
    property HasAlpha: Boolean read FHasAlpha write FHasAlpha;
  end;

FBitmap32: TMyBitmap32



grüsse,
Ulrich
Rool Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 211



BeitragVerfasst: Mo 14.05.07 10:38 
Titel: ..
ich habe es inzwischen mittels dieser bibliothek geschafft:
www.geocities.com/gc...ltpe/code/index.html

werde mir deine (wesentlich schlankere version) aber auch nochmal ansehen. vielen dank!!

_________________
MFG Rool
uko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: Mo 14.05.07 10:48 
Dank an Dich für den Link. Die Lib kannte ich noch gar nicht. Auf den ersten Blick scheinen ein paar für mich interessante Dinge drinnen zu sein.

grüsse,
Ulrich