**** PNGImage von 10.3 ***
{Assigns this TPngImage to another object}
procedure TPngImage.AssignTo(Dest: TPersistent);
{$IFDEF UseDelphi}
function DetectPixelFormat: TPixelFormat;
begin
with Header
do
begin
{Always use 24bits for partial transparency}
if TransparencyMode = ptmPartial
then
DetectPixelFormat := pf24bit
else
case BitDepth
of
{Only supported by COLOR_PALETTE}
1: DetectPixelFormat := pf1bit;
2, 4: DetectPixelFormat := pf4bit;
{8 may be palette or r, g, b values}
8, 16:
case ColorType
of
COLOR_RGB, COLOR_GRAYSCALE: DetectPixelFormat := pf24bit;
COLOR_PALETTE: DetectPixelFormat := pf8bit;
else raise Exception.Create('
');
end {case ColorFormat of}
else raise Exception.Create('
');
end {case BitDepth of}
end {with Header}
end;
var
TRNS: TChunkTRNS;
{$ENDIF}
begin
{If the destination is also a TPngImage make it assign}
{this one}
if Dest
is TPngImage
then
TPngImage(Dest).AssignPNG(Self)
{$IFDEF UseDelphi}
{In case the destination is a bitmap}
else if (Dest
is TBitmap)
and HeaderPresent
then
begin
TBitmap(Dest).SetSize(Width, Height);
if (TransparencyMode = ptmPartial)
then
begin
TBitmap(Dest).PixelFormat := pf32bit;
TBitmap(Dest).AlphaFormat := afDefined;
// Die 2 folgenden Zeilen sind neu: Wer hat sich diesen Blödsinn überlegt?!
TBitmap(Dest).Canvas.Brush.Color := 0;
// <<< zumindest das hier sollte vom Anwender wählbar sein, also als Property zur Verfügung stehen.
TBitmap(Dest).Canvas.FillRect(Bounds(0,0,Width, Height));
end
else
begin
TBitmap(Dest).PixelFormat := DetectPixelFormat;
TBitmap(Dest).AlphaFormat := afIgnored;
end;
if Palette <> 0
then
TBitmap(Dest).Palette := CopyPalette(Palette);
if (TransparencyMode = ptmBit)
then
begin
TRNS := TChunkTRNS(Chunks.ItemFromClass(TChunkTRNS));
TBitmap(Dest).TransparentColor := TRNS.TransparentColor;
TBitmap(Dest).Transparent := True;
SetStretchBltMode(TBitmap(Dest).Canvas.Handle, COLORONCOLOR);
StretchDiBits(TBitmap(Dest).Canvas.Handle, 0, 0, Width, Height, 0, 0,
Width, Height, Header.ImageData,
pBitmapInfo(@Header.BitmapInfo)^, DIB_RGB_COLORS, SRCCOPY)
end {if (TransparencyMode = ptmBit)}
else
TBitmap(Dest).Canvas.Draw(0, 0, Self);
end
else
{Unknown destination kind}
inherited AssignTo(Dest);
{$ENDIF}
end;