delphi操作png的单元pngimage.pas包括引用的ZlibExApi.pas和 PngLang.pas

这篇博客分享了如何在Delphi 2009及以后的版本中操作PNG图像,提供了源码下载链接,包括pngimage.pas、ZlibExApi.pas和PngLang.pas三个单元。当程序无法找到pngimage单元时,这些源码可能有所帮助。文章还简单展示了代码的使用方法,但未处理内存泄露问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有需要的可以去这里下载源码。http://download.csdn.net/detail/sushengmiyan/4662715

delphi操作png是在delphi2009版本之后(网上这么说的)

于是乎。。

我找了源码来共享。。

希望对大家有帮助。

当你的程序找不到pngimage这个单元的时候。。。

这段代码会帮助到你。。。

当你的不使用delphi...

或者你的可以正常使用pngimage。。。

那么。。。。

这里你就可以忽略了。。。

下面就是一个简单的用法。可以参考下下~

  procedure doSomething(ms: TMemoryStream);
  var
    Buffer:Word;
    AjpgFile: TJPEGImage;
    ApngFile: TPNGObject;
  begin
    ms.Position := 0;  
    if ms.Size = 0 then
      Exit;
    ms.ReadBuffer(Buffer,2); //读取文件的前2个字节,放到Buffer里面
    if Buffer=$4D42 then //如果前两个字节是以4D42[低位到高位]
    begin
      ShowMessage('BMP'); //那么这个是BMP格式的文件
    end
    else if Buffer=$D8FF then //如果前两个字节是以D8FF[低位到高位]
    begin
      ms.Position := 0;
      AjpgFile := TJPEGImage.Create;
      AjpgFile.LoadFromStream(ms);
      Image1.Picture.Graphic := AjpgFile;
    end
    else if Buffer=$4947 then
    begin
      ShowMessage('GIF');
    end
    else if Buffer=$5089 then
    begin
      ms.Position := 0;
      ApngFile := TPNGObject.Create;
      ApngFile.LoadFromStream(ms);
      Image1.Picture.Graphic := ApngFile;
    end;
  end;

不好意思,写的太烂。内存泄露没处理

   else if Buffer=$D8FF then //如果前两个字节是以D8FF[低位到高位]
    begin
      ms.Position := 0;
      AjpgFile := TJPEGImage.Create;
      try
        AjpgFile.LoadFromStream(ms);
        Image1.Picture.Graphic := AjpgFile;
      finally
        AjpgFile.Free;
      end;
    end
    else if Buffer=$4947 then
    begin
      ShowMessage('GIF');
    end
    else if Buffer=$5089 then
    begin
      ms.Position := 0;
      ApngFile := TPNGObject.Create;
      try
        ApngFile.LoadFromStream(ms);
        Image1.Picture.Graphic := ApngFile;
      finally
        ApngFile.Free;
      end;
    end;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值