我有一个WPF应用程序,其中包含一个自定义控件。该自定义控件将自己呈现为位图,我能够使用以下代码来确定使用什么分辨率以使位图与显示器分辨率相匹配。
PresentationSource ps = PresentationSource.FromVisual(this);
if (ps != null)
{
pixelsPerLogicalUnitX = ps.CompositionTarget.TransformToDevice.M11;
pixelsPerLogicalUnitY = ps.CompositionTarget.TransformToDevice.M22;
}
很不幸,当我通过PrintDialog将此控件发送到打印机时,PresentationSource为空,因此我不知道DPI。
有没有办法获取打印机的DPI(或PresentationSource)?