作爲羅德里戈指出,Header.BitDepth是使用的值。缺點是你必須根據ColorType來解釋它。您可能會發現裏面的功能BytesForPixels評論一些提示在PngImage.pas:
{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;
正如你看到的,對於ARGB(= COLOR_RGBALPHA)位深值取每個顏色部分加上個別alpha值。所以位深度= 8將導致針對每個像素的32位的值。
但是,當一個ARGB32位png被加載IntToStr(TPNGImage(Image1.Picture.Graphic).Header.BitDepth)返回8而不是32? – Bill 2012-03-29 16:40:39
哎呀@UweRaabe爲您提供關鍵的見解,而我寫我更新的答案。 – RRUZ 2012-03-29 17:10:45