开发者

How to get the DPI of the printer in WPF

开发者 https://www.devze.com 2023-02-02 11:49 出处:网络
I have a WPF application with a custom control.The custom control renders itself to a bitmap and I am able to use the following code to figure o开发者_开发百科ut what resolution to use so that the bit

I have a WPF application with a custom control. The custom control renders itself to a bitmap and I am able to use the following code to figure o开发者_开发百科ut what resolution to use so that the bitmap matches the display resolution.

        PresentationSource ps = PresentationSource.FromVisual(this);
        if (ps != null)
        {
            pixelsPerLogicalUnitX = ps.CompositionTarget.TransformToDevice.M11;
            pixelsPerLogicalUnitY = ps.CompositionTarget.TransformToDevice.M22;
        }

Unfortunately, when I send this control to the printer through a PrintDialog, the PresentationSource is null so I don't know the DPI.

Is there a way to get the DPI ( or a PresentationSource ) for the printer?


you are looking for PrintTicket.PageResolution

http://msdn.microsoft.com/en-us/library/system.printing.printticket.pageresolution.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消