![]() |
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 |
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); ... |
AW: WMF To PNG
Danke, das geht auf dem Canvas.
Aber mit png.SaveToFile(...); ist die Transparenz wieder weg. |
AW: WMF To PNG
Zitat:
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). |
AW: WMF To PNG
Hast du ein Stück Code?
|
AW: WMF To PNG
COLOR_RGBALPHA? :stupid:
Zitat:
Ist das pro Farbe oder insgesamt? Vielleicht so?
Delphi-Quellcode:
und dann ohne FillRect nur noch das WMF drauf.
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(... Ist das WMF auch transparent? Und probieren, ob mit oder ohne Setzen des Brush. |
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:
Ein FillRect (und das Setzen der Brush-Farbe davor) wäre unnötig, wenn man wüsste, was die Standardfarbe von TPngImage ist.
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; |
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