简体   繁体   English

Delphi 7,加载PNG到TImage

[英]Delphi 7, load PNG to TImage

Just want to load a.PNG, tried with my LoadPic() using OleGraphic that works with other formats, but it failed on PNG.只想加载一个.PNG,尝试使用适用于其他格式的 OleGraphic 与我的 LoadPic() 一起使用,但它在 PNG 上失败了。

The goal is to copy the image to a hidden bitmap whence it is then masked and copied to a visible working image canvas.目标是将图像复制到隐藏的 bitmap,然后将其屏蔽并复制到可见的工作图像 canvas。 Feel free to suggest something else if CopyRect doesn't do this.如果 CopyRect 不这样做,请随意提出其他建议。

But the main question: Load PNG.但主要问题是:加载 PNG。 How?如何? I've found a lot of pages (f.ex. TPNGImage), but all the resources and links on the web are dead, gone or not downloadable.我找到了很多页面(例如 TPNGImage),但是 web 上的所有资源和链接都已失效、消失或无法下载。

Delphi 7 doesn't support PNG natively. Delphi 7 本身不支持 PNG。 There are several third party components that will let you add that support.有几个第三方组件可让您添加该支持。 For example, on Torry's site .例如,在Torry 的网站上

Recent versions of Delphi support PNG natively, amongst many other enhancements, and you would be well advised to upgrade.最新版本的 Delphi 原生支持 PNG,以及许多其他增强功能,建议您升级。

I will use GraphicEx from Soft Gems for now.我现在将使用Soft GemsGraphicEx Thanks for helpful answers!感谢您提供有用的答案!

Download from below...从下面下载...

http://delphi.pjh2.de/articles/graphic/png.php http://delphi.pjh2.de/articles/graphic/png.php

It is very easy to handle.png images with delphi 7... Just add it into uses... and create a png object...使用 delphi 7 处理.png 图像非常容易...只需将其添加到使用...并创建一个 png object...

GraphicEx by Soft Gems has been moved to https://github.com/mike-lischke/GraphicEx Soft Gems 的 GraphicEx 已移至https://github.com/mike-lischke/GraphicEx

An explaination regarding the move can be found at http://www.soft-gems.net/index.php/libs/43-graphicex-on-github可以在http://www.soft-gems.net/index.php/libs/43-graphicex-on-github找到有关此移动的说明

I added GraphicEx to my Delphi 6 project and it worked out of the box but when I tested it with Delphi 5 it did not.我将 GraphicEx 添加到我的 Delphi 6 项目中,它开箱即用,但是当我用 Delphi 5 对其进行测试时,它没有。

Regardless, it works well and implements not only PNG images but also many others which are configurable from GraphicConfiguration.inc:无论如何,它运行良好,不仅实现了 PNG 图像,还实现了许多其他可从 GraphicConfiguration.inc 配置的图像:

// Pick your preferred image formats here or leave them all enabled. By disabling
// certain formats which are not of interest you can save some memory.
{$define UseLZW}  //patent is out, yay!
{$define SGIGraphic}             // *.bw, *.rgb, *.rgba, *.sgi images are supported
{$define AutodeskGraphic}        // *.cel, *.pic images
{-$define NewTIFFGraphic}            // *.tif, *.tiff images
{$define OldTIFFGraphic}
{$define TargaGraphic}           // *.tga, *.vst, *.icb, *.vda, *.win images
{$define PCXGraphic}             // *.pcx, *.pcc, *.scr images
{$define PCDGraphic}             // *.pcd images
{$define PortableMapGraphic}     // *.ppm, *.pgm, *.pbm images
{$define CUTGraphic}             // *.cut (+ *.pal) images
{$define GIFGraphic}             // *.gif images
{$define RLAGraphic}             // *.rla, *.rpf images
{$define PhotoshopGraphic}       // *.psd, *.pdd images
{$define PaintshopProGraphic}    // *.psp images
{$define PortableNetworkGraphic} // *.png images
{$define EPSGraphic}             // *.eps images
{$define ArtsAndLettersGraphic}  // *.ged images

The small Open Source SynGdiPlus library is able to load and save gif, tiff and png pictures .小型开源 SynGdiPlus 库能够加载和保存 gif、tiff 和 png 图片

It will call the GdiPlus.dll library, which is available since Windows XP.它将调用 GdiPlus.dll 库,该库自 Windows XP 起可用。

It's fast and reliable.它快速可靠。

The same unit is able to render any GDI metafile with anti-aliasing: you write on a regular TCanvas, then it's drawn with anti-aliasing using GDI+.同一单元能够渲染任何具有抗锯齿的 GDI 图元文件:您在常规 TCanvas 上书写,然后使用 GDI+ 进行抗锯齿绘制。 Small code change, greater rendering.小的代码更改,更大的渲染。

Open Source unit, working from Delphi 6 up to XE.开源单元,从 Delphi 6 到 XE。

You can download the latest version from http://synopse.info/fossil/finfo?name=SynGdiPlus.pas您可以从http://synopse.info/fossil/finfo?name=SynGdiPlus.pas下载最新版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM