<PackageReference Include="System.Drawing.Common" Version="10.0.0-preview.1.25080.3" />

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.