Als Rodrigo wies darauf hin, ist Header.BitDepth der Wert zu verwenden. Der Haken ist, dass Sie es abhängig vom ColorType interpretieren müssen. Sie können einige Hinweise in den Kommentaren innerhalb Funktion BytesForPixels in PngImage.pas finden:
{Calculates number of bytes for the number of pixels using the}
{color mode in the paramenter}
function BytesForPixels(const Pixels: Integer; const ColorType,
BitDepth: Byte): Integer;
begin
case ColorType of
{Palette and grayscale contains a single value, for palette}
{an value of size 2^bitdepth pointing to the palette index}
{and grayscale the value from 0 to 2^bitdepth with color intesity}
COLOR_GRAYSCALE, COLOR_PALETTE:
Result := (Pixels * BitDepth + 7) div 8;
{RGB contains 3 values R, G, B with size 2^bitdepth each}
COLOR_RGB:
Result := (Pixels * BitDepth * 3) div 8;
{Contains one value followed by alpha value booth size 2^bitdepth}
COLOR_GRAYSCALEALPHA:
Result := (Pixels * BitDepth * 2) div 8;
{Contains four values size 2^bitdepth, Red, Green, Blue and alpha}
COLOR_RGBALPHA:
Result := (Pixels * BitDepth * 4) div 8;
else
Result := 0;
end {case ColorType}
end;
Wie Sie sehen, für ARGB (= COLOR_RGBALPHA) der bitdepth Wert für jede Farbe Teil genommen wird und der Alpha-Wert einzeln. So ergibt BitDepth = 8 einen 32-Bit-Wert für jedes Pixel.
Aber wenn ein ARGB32-Bit-Png geladen wird IntToStr (TPNGImage (Image1.Picture.Graphic) .Header.BitDepth) gibt 8 statt 32 zurück? – Bill
Oops @UweRaabe gibt Ihnen die wichtigsten Einblicke, während ich meine aktualisierte Antwort schreibe. – RRUZ