毫米转像素dpi

public static double MillimeterToPixel_X(double length) //length是毫米,1厘米=10毫米
        {
            System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();
            System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle);

            //1英寸=25.4mm=96DPI,那么1mm=96/25.4DPI
            return (((double)g.DpiX / 25.4) * (double)length);
        }
        public static double MillimeterToPixel_Y(double length) //length是毫米,1厘米=10毫米
        {
            System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();
            System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle);

            //1英寸=25.4mm=96DPI,那么1mm=96/25.4DPI
            return (((double)g.DpiY / 25.4) * (double)length);
        }

 

posted @ 2021-11-12 15:48  212的s  阅读(235)  评论(0)    收藏  举报