uses Direct2D, D2D1; procedure TForm1.FormPaint(Sender: TObject); var cvs: TDirect2DCanvas; iLayer: ID2D1Layer; rLayerParameters: TD2D1LayerParameters; wic: TWICImage; R: TRect; iEllipse: ID2D1EllipseGeometry; begin wic := TWICImage.Create; wic.LoadFromFile('C:\Temp\Test.png'); R := Rect(0, 0, wic.Width, wic.Height); {几何图形} D2DFactory.CreateEllipseGeometry(D2D1Ellipse(D2D1PointF(wic.Width/2, wic.Height/2), wic.Width/2, wic.Height/2), iEllipse); cvs := TDirect2DCanvas.Create(Canvas, ClientRect); cvs.RenderTarget.SetTransform(TD2DMatrix3x2F.Translation((ClientWidth-wic.width)/2, (ClientHeight-wic.height)/2)); cvs.BeginDraw; cvs.RenderTarget.CreateLayer(nil, iLayer); rLayerParameters.contentBounds := R; rLayerParameters.geometricMask := iEllipse; //! rLayerParameters.maskAntialiasMode := D2D1_ANTIALIAS_MODE_PER_PRIMITIVE; rLayerParameters.maskTransform := TD2DMatrix3x2F.Identity; rLayerParameters.opacity := 1.0; // rLayerParameters.opacityBrush := nil; rLayerParameters.layerOptions := D2D1_LAYER_OPTIONS_NONE; cvs.RenderTarget.PushLayer(rLayerParameters, iLayer); cvs.StretchDraw(R, wic); cvs.RenderTarget.PopLayer; cvs.EndDraw; cvs.Free; wic.Free; end; procedure TForm1.FormResize(Sender: TObject); begin Repaint; end;
效果图:

分类:
Direct2D
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
2010-04-05 学 Win32 汇编[9]: 子过程中的变量声明