gpt4 book ai didi

delphi - 如何将 TGPGraphics 内容绘制到 Canvas 上

转载 作者:行者123 更新时间:2023-12-02 01:39:12 31 4
gpt4 key购买 nike

我正在尝试将以下 TGPGraphics 的内容复制到 Canvas 上,但它不起作用。我在这里缺少什么?

function DrawGlyph(bm: TObject; Canvas: TCanvas; X, Y: Integer): Integer;
var
O: TGPBitmap;
G: TGPGraphics;
begin
if (bm is TGPImage) then
begin
O := TGPBitmap.Create(16, 16, PixelFormat32bppARGB);
try
G := TGPGraphics.Create(O);
try
G.SetCompositingMode(CompositingModeSourceCopy);
G.SetInterpolationMode(InterpolationModeHighQualityBicubic);
G.SetPixelOffsetMode(PixelOffsetModeHighQuality);
G.SetSmoothingMode(SmoothingModeHighQuality);
G.DrawImage(TGPImage(bm), 0, 0, O.GetWidth, O.GetHeight);

BitBlt(Canvas.Handle, X, Y, O.GetWidth, O.GetHeight, G.GetHDC, 0, 0, SRCCOPY);
finally
G.Free;
end;

finally
O.Free;
end;
end;
end;

最佳答案

您可以直接使用构造函数将TGPGraphics绘制到Canvas上

TGPGraphics.Create(hdc: HDC)

您也不需要 O: TGPBitmap 例如:

function DrawGlyph(bm: TObject; Canvas: TCanvas; X, Y: Integer): Integer;
var
G: TGPGraphics;
begin
// Result := ???
if (bm is TGPImage) then
begin
Canvas.Lock;
try
G := TGPGraphics.Create(Canvas.Handle);
try
G.SetCompositingMode(CompositingModeSourceCopy);
G.SetInterpolationMode(InterpolationModeHighQualityBicubic);
G.SetPixelOffsetMode(PixelOffsetModeHighQuality);
G.SetSmoothingMode(SmoothingModeHighQuality);
G.DrawImage(TGPImage(bm), X, Y, 16, 16);
finally
G.Free;
end;
finally
Canvas.Unlock;
end;
end;
end;

关于delphi - 如何将 TGPGraphics 内容绘制到 Canvas 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41274112/

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