ng System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; public class Dp_pixels_convert { public static void TransformToDP(int pixels_w,int pixels_h,out double unitX,out double unitY) { Graphics g = Graphics.FromHwnd(IntPtr.Zero); double rate_x= g.DpiX / 96.0; double rate_y = g.DpiY / 96.0; unitX = pixels_w / rate_x; unitY = pixels_h / rate_y; } public static void TransformToPixels(double unitX, double unitY, out int pixelX, out int pixelY) { using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { pixelX = (int)((g.DpiX / 96) * unitX); pixelY = (int)((g.DpiY / 96) * unitY); } } }
沒有留言:
張貼留言