<PackageReference Include="System.Drawing.Common" Version="9.0.5" />

IDeviceContext

public interface IDeviceContext : IDisposable
Defines methods for obtaining and releasing an existing handle to a Windows device context.
IntPtr GetHdc()

Returns the handle to a Windows device context.

void ReleaseHdc()

Releases the handle of a Windows device context.