public class DPIUtils
{
private static double _dpiX = 1.0;
private static double _dpiY = 1.0;
public static double DPIX
{
get
{
return DPIUtils._dpiX;
}
}
public static double DPIY
{
get
{
return DPIUtils._dpiY;
}
}
public static void Init(System.Windows.Media.Visual visual)
{
Matrix transformToDevice = System.Windows.PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice;
DPIUtils._dpiX = transformToDevice.M11;
DPIUtils._dpiY = transformToDevice.M22;
}
public static Point DivideByDPI(Point p)
{
return new Point(p.X / DPIUtils.DPIX, p.Y / DPIUtils.DPIY);
}
public static Rect DivideByDPI(Rect r)
{
return new Rect(r.Left / DPIUtils.DPIX, r.Top / DPIUtils.DPIY, r.Width, r.Height);
}
}
WPF中根据DPI获取准确坐标点啊,布布扣,bubuko.com
时间: 2024-10-19 04:24:33