【发布时间】:2020-02-04 12:06:30
【问题描述】:
出于测试目的,在我的 Delphi 10.3 应用程序中,我想用每个图像的尺寸来装饰 TImageCollection 中的图像。对于位图,这没问题,但对于 PNG 文件,我无法在该画布上绘画,也无法在 TWICImage 中将 BMP 分配给 PNG,因为运行时异常“无法将 TPngImage 分配给 TWICImage”。
procedure DecorateImageCollection(imcMainMisc: TImageCollection);
var
i, j: Integer;
bmp:Graphics.TBitmap;
item:TImageCollectionItem;
img:TImageCollectionSourceItem;
begin
for i := 0 to imcMainMisc.Count - 1 do
begin
item:=imcMainMisc.Images.Items[i];
for j := 0 to item.SourceImages.Count - 1 do
begin
img:=item.SourceImages.Items[j];
case img.Image.ImageFormat of
wifBmp:
;
wifPng:
begin
bmp:=Graphics.TBitmap.Create;
try
bmp.Assign(img.Image);
bmp.Canvas.Font.Name:='Small Fonts';
bmp.Canvas.Font.Size:=6;
bmp.Canvas.Font.Color:=clRed;
bmp.Canvas.Brush.Style:=bsClear;
bmp.Canvas.Pen.Style:=psSolid;
bmp.Canvas.TextOut(0, 0, IntToStr(bmp.Height));
// *cannot assign a TPngImage to a TWICImage*
img.Image.Assign(bmp);
finally
bmp.Free;
end;
end;
wifJpeg:
;
wifGif:
;
wifTiff:
;
wifWMPhoto:
;
wifOther:
;
end;
end;
end;
end;
我希望这样的操作应该很简单,但我还没有发现如何。
谢谢!
【问题讨论】:
-
你在uses子句中添加了“pngimage”吗?:docwiki.embarcadero.com/Libraries/Rio/en/…
-
如果你有旧版本的 Delphi 没有附带 pngimage,请下载组件:cc.embarcadero.com/Item/26127
-
我正在使用最新的 Delphi 版本 (10.3) 并且遇到运行时错误(无法将 TPngImage 分配给 TWICImage)。