Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   WMF To PNG (https://www.delphipraxis.net/215295-wmf-png.html)

tomkupitz 8. Jun 2024 17:07

WMF To PNG
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,

ich möchte das WMF im Anhang in ein transparentes PNG konvertieren. Bei den gängigen Bsp. im Zetz fehlt am Ende die Transparenz. Wie kann ich hier vorgehen?

Danke und beste Grüße

Uwe Raabe 8. Jun 2024 18:05

AW: WMF To PNG
 
Probier mal dies:
Delphi-Quellcode:
  wmf := TMetafile.Create;
  wmf.LoadFromFile(...);

  png := TPngImage.CreateBlank(COLOR_RGB, 16, wmf.Width, wmf.Height);
  png.Transparent := True;
  png.TransparentColor := clNone;
  png.Canvas.Brush.Color := png.TransparentColor;
  png.Canvas.FillRect(TRect.Create(0, 0, png.Width, png.Height));
  png.Canvas.Draw(0, 0, wmf);
  ...

tomkupitz 8. Jun 2024 19:22

AW: WMF To PNG
 
Danke, das geht auf dem Canvas.

Aber mit png.SaveToFile(...); ist die Transparenz wieder weg.

Redeemer 8. Jun 2024 20:10

AW: WMF To PNG
 
Zitat:

Zitat von tomkupitz (Beitrag 1537574)
Aber mit png.SaveToFile(...); ist die Transparenz wieder weg.

Nee, die war nie da. Wo soll die auch sein mit COLOR_RGB?

Ich male die WMF auf zwei opake PNGs, eine mit schwarzem Hintergrund und eine mit weißem. Dann erstelle ich eine dritte mit PNG und wo die beiden PNGs gleich sind, wird die Farbe übernommen, anderswo ist es transparent. Auch hilfreich um andere möglicherweise transparenten Eingaben zu konvertieren (z.B. GIF).

tomkupitz 8. Jun 2024 21:00

AW: WMF To PNG
 
Hast du ein Stück Code?

himitsu 8. Jun 2024 23:07

AW: WMF To PNG
 
COLOR_RGBALPHA? :stupid:

Zitat:

Delphi-Quellcode:
png := TPngImage.CreateBlank(COLOR_RGB, 16,

16 Bit Farbtiefe?

Ist das pro Farbe oder insgesamt?


Vielleicht so?
Delphi-Quellcode:
png := TPngImage.CreateBlank(COLOR_RGBALPHA, 8, wmf.Width, wmf.Height);
png.Canvas.Draw(0, 0, wmf);
png.SafeToFile(...

png := TPngImage.CreateBlank(COLOR_RGBALPHA, 16, wmf.Width, wmf.Height);
png.Canvas.Draw(0, 0, wmf);
png.SafeToFile(...

png := TPngImage.CreateBlank(COLOR_RGB, 8 {oder 16}, wmf.Width, wmf.Height);
png.CreateAlpha;
png.Canvas.Draw(0, 0, wmf);
png.SafeToFile(...

png := TPngImage.Create;
png.Resize(wmf.Width, wmf.Height);
png.CreateAlpha;
png.Canvas.Draw(0, 0, wmf);
png.SafeToFile(...
und dann ohne FillRect nur noch das WMF drauf.
Ist das WMF auch transparent?

Und probieren, ob mit oder ohne Setzen des Brush.

Redeemer 8. Jun 2024 23:53

AW: WMF To PNG
 
Die 8 sind pro Kanal. PNG kann keine 16-Bit insgesamt.

Graphic ist dein EMF. Der Rest ist klar. Das Ergebnis heißt TempPNG.
Delphi-Quellcode:
        TempPNG := TPNGImage.CreateBlank(COLOR_RGBALPHA, 8, Graphic.Width * Supersample, Graphic.Height * Supersample);
        TempPNG2 := TPNGImage.CreateBlank(COLOR_RGB, 8, Graphic.Width * Supersample, Graphic.Height * Supersample);
        try
          TempPNG.Canvas.Brush.Color := clBlack;
          TempPNG2.Canvas.Brush.Color := clWhite;
          TempPNG.Canvas.FillRect(Rect(0, 0, Graphic.Width * Supersample, Graphic.Height * Supersample));
          TempPNG2.Canvas.FillRect(Rect(0, 0, Graphic.Width * Supersample, Graphic.Height * Supersample));
          TempPNG.Canvas.StretchDraw(Rect(0, 0, Graphic.Width * Supersample, Graphic.Height * Supersample), Graphic);
          TempPNG2.Canvas.StretchDraw(Rect(0, 0, Graphic.Width * Supersample, Graphic.Height * Supersample), Graphic);
          for y := 0 to TempPNG.Height - 1 do
          begin
            ScanLine := TempPNG.AlphaScanline[y];
            for x := 0 to TempPNG.Width - 1 do
            ScanLine^[x] := Byte((TempPNG.Pixels[x,y] = TempPNG2.Pixels[x,y])) * 255;
          end;
        finally
          TempPNG2.Free;
        end;
Ein FillRect (und das Setzen der Brush-Farbe davor) wäre unnötig, wenn man wüsste, was die Standardfarbe von TPngImage ist.

tomkupitz 9. Jun 2024 15:31

AW: WMF To PNG
 
@Redeemer

Danke das funktioniert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz