Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. RenderTargetBitmap DPI for drawing application
  2. // Get system DPI
  3. Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
  4. if (m.M11 > 0 && m.M22 > 0)
  5. {
  6.     dpiXFactor = m.M11;
  7.     dpiYFactor = m.M22;
  8. }
  9. else
  10. {
  11.     // Sometimes this can return a matrix with 0s. Fall back to assuming normal DPI in this case.
  12.     dpiXFactor = 1;
  13.     dpiYFactor = 1;
  14. }