我正在尝试将以下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
绘制到画布上
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/