gpt4 book ai didi

delphi - 如何获取 TPNGImage 的像素格式或位深度

转载 作者:行者123 更新时间:2023-12-03 15:04:53 27 4
gpt4 key购买 nike

使用 Delphi 2010,您可以使用

获取 jpg 文件的像素格式
TJPEGImage ( Image.Picture.Graphic ).PixelFormat  

有没有办法获取 TPNGImage 的像素格式或位深度?

我尝试了这个,但它返回了错误的位深度:

 if Lowercase ( ExtractFileExt ( FPath ) ) = '.png' then
StatusBar1.Panels [ 4 ].Text := ' Color Depth: ' + IntToStr( TPNGImage ( Image.Picture.Graphic ).Header.ColorType ) + '-bit';

最佳答案

您必须使用BitDepth字段

TPNGImage(Image.Picture.Graphic ).Header.BitDepth) 

并使用ColorType字段,您可以编写这样的函数

function BitsForPixel(const AColorType,  ABitDepth: Byte): Integer;
begin
case AColorType of
COLOR_GRAYSCALEALPHA: Result := (ABitDepth * 2);
COLOR_RGB: Result := (ABitDepth * 3);
COLOR_RGBALPHA: Result := (ABitDepth * 4);
COLOR_GRAYSCALE, COLOR_PALETTE: Result := ABitDepth;
else
Result := 0;
end;
end;

并像这样使用

procedure TForm72.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr( BitsForPixel(
TPNGImage ( Image1.Picture.Graphic ).Header.ColorType,
TPNGImage ( Image1.Picture.Graphic ).Header.BitDepth
)));
end;

关于delphi - 如何获取 TPNGImage 的像素格式或位深度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9929387/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com