, PNG TBitmap32, . PNG. "Bitmap.DrawMode: = dmTransparent" "OuterColor". PNG TBitmpa32, DrawMode: = dmBlend OuterColor.
, PNG TBitmap32. TPngImage Vcl.Imaging.pngimage( Delphi XE2 ) , , , - PNG .., PNG ( ) - TBitmap32. , TPngImage , RGB , - .
, PNG TBitmap32 , :
(1) "LoadPNGintoBitmap32" http://graphics32.org/wiki/FAQ/ImageFormatRelated
- , -, 0 255, , ( ). RGB, , . : Delphi, GR32 + PngObject: Bitmap32
, , - TBitmap32. - ( RGB), RGB, , , .
(2) "LoadBitmap32FromPNG" gr32ex: https://code.google.com/archive/p/gr32ex/
- , (1), , (1).
, :
-
, . , - PNGObject.RemoveTransparency. , - . , . , - TBitmap32 , Transparent Png to TBitmap32, , .
procedure LoadPNGintoBitmap32(DstBitmap: TBitmap32; SrcStream: TStream; out AlphaChannelUsed: Boolean);
var
PNGObject: TPngImage;
PixelPtr: PColor32;
AlphaPtr: PByte;
SaveAlpha: PByte;
I, AlphaSize: Integer;
begin
AlphaChannelUsed := False;
PNGObject := TPngImage.Create;
try
PNGObject.LoadFromStream(SrcStream);
AlphaPtr := PByte(PNGObject.AlphaScanline[0]);
if Assigned(AlphaPtr) then
begin
AlphaSize := PNGObject.Width * PNGObject.Height;
if AlphaSize <= 0 then raise Exception.Create('PNG files with zero dimensions are not supported to be loaded to TBitmap32');
GetMem(SaveAlpha, AlphaSize);
try
Move(AlphaPtr^, SaveAlpha^, AlphaSize);
PNGObject.RemoveTransparency;
DstBitmap.Assign(PNGObject);
DstBitmap.ResetAlpha;
PixelPtr := PColor32(@DstBitmap.Bits[0]);
AlphaPtr := SaveAlpha;
for I := 0 to AlphaSize-1 do
begin
PixelPtr^ := (PixelPtr^ and $00FFFFFF) or (TColor32(AlphaPtr^) shl 24);
Inc(PixelPtr);
Inc(AlphaPtr);
end;
finally
FreeMem(SaveAlpha, AlphaSize);
end;
AlphaChannelUsed := True;
end else
if PNGObject.TransparencyMode = ptmNone then
begin
DstBitmap.Assign(PNGObject);
end else
begin
raise Exception.Create('Paletted PNG images are not supported in LoadPNGintoBitmap32, transparency cannot be stored to TBitmap32');
end;
finally
FreeAndNil(PNGObject);
end;
end;