加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 如何获取TPNGImage的pixelformat或bitdepth

发布时间:2020-12-15 09:48:15 所属栏目:大数据 来源:网络整理
导读:使用Delphi 2010,您可以获得jpg文件的pixelformat TJPEGImage ( Image.Picture.Graphic ).PixelFormat 有没有办法获得TPNGImage的pixelformat或bitdepth? 我试过这个,但它返回错误的bitdepth: if Lowercase ( ExtractFileExt ( FPath ) ) = '.png' then St
使用Delphi 2010,您可以获得jpg文件的pixelformat

TJPEGImage ( Image.Picture.Graphic ).PixelFormat

有没有办法获得TPNGImage的pixelformat或bitdepth?

我试过这个,但它返回错误的bitdepth:

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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读