Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pauldendulk/bceb790607660471b2b674e92721504a to your computer and use it in GitHub Desktop.
Save pauldendulk/bceb790607660471b2b674e92721504a to your computer and use it in GitHub Desktop.
GetSkiaScale
private float GetSkiaScale()
{
var presentationSource = PresentationSource.FromVisual(this);
if (presentationSource == null) throw new Exception("PresentationSource is null");
var compositionTarget = presentationSource.CompositionTarget;
if (compositionTarget == null) throw new Exception("CompositionTarget is null");
var m = compositionTarget.TransformToDevice;
var dpiX = m.M11;
var dpiY = m.M22;
if (dpiX != dpiY)
throw new ArgumentException();
return (float)dpiX;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment