请问一张图片BMP 的像素为 宽128 高128
要如何换算成 mm ,有没有甚么方法或工具?

解决方案 »

  1.   

    讨论区有人提到
    1cm    = 567twips   
    1pixel = 15twips

    但是还不是很能理解
      

  2.   

    Point   Conv(Graphics   g,Point   pointf)   
      {   
      pointf.X*=g.DpiX/25.4f;   
      pointf.Y*=g.DpiY/25.4f;   
      return   pointf;   
      }   
      

  3.   

    Hi wuyq11
    能不能解说一下这用法及意思?想要更了解清楚~ 感谢Point  Conv(Graphics  g,Point  pointf)  
      {  
      pointf.X*=g.DpiX/25.4f;  
      pointf.Y*=g.DpiY/25.4f;  
      return  pointf;  
      } 
      

  4.   

    这取决于分辨率。在一个72DPI的显示器上,1英寸(2540mm)能显示72像素,那么128像素显示为4.5cm。
    在一个600DPI的打印机上,600像素为1英寸,128像素打印为0.5cm。文件右键属性,可以看到图片文件一般都有DPI的属性,图像编辑器可以利用这个来计算图像的理想尺寸。
    lengthInMillimeter = pixels / DPI * 2540 
      

  5.   

    C#中以像素作为尺寸单位,像素是一种相对的尺寸概念,与毫米的转换与当前显示器的分辨率有关。在不同分辨率下转换的系数不同。 
    借助GDI可以完成毫米至像素的转换。public static double MillimetersToPixelsWidth(double length)
    {
        System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();
        System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle);
        IntPtr hdc = g.GetHdc();
        int width = GetDeviceCaps(hdc, 4);     // HORZRES 
        int pixels = GetDeviceCaps(hdc, 8);     // BITSPIXEL
        g.ReleaseHdc(hdc);
        return (((double)pixels / (double)width) * (double)length);
    }
    [DllImport("gdi32.dll")]
    private static extern int GetDeviceCaps(IntPtr hdc, int Index);
      
    像素与毫米的转换
    转换还需要知道另一个参数:DPI(每英寸多少点)
    象素数 / DPI = 英寸数
    英寸数 * 25.4 = 毫米数 对于显示设备,不管是打印机还是屏幕,都有一种通用的方法
    先用GetDeviceCaps(设备句柄,LOGPIXELSX)
    或者
    GetDeviceCaps(设备句柄,LOGPIXELSY)获得设备每英寸的像素数
    分别记为:px 和 py
    一英寸等于25.4mm
    那么毫米换算成像素的公式为 
    水平方向的换算: x * px /25.4
    垂直方向的换算: y * py /25.4
    像素换算为毫米 x * 25.4 / px
    在程序中这么写
    MyControl.Height := 10{mm} * PixelsPerInch * 10 div 254;
      

  6.   


                Bitmap Bmp = new Bitmap(128, 128);            float Width = Bmp.HorizontalResolution * 25.4F;
                float Height = Bmp.VerticalResolution * 25.4F;
      

  7.   

    是除。。1         X   
    ---- = ------
    25.4     Bmp.HorizontalResolution        
                float Width = Bmp.HorizontalResolution /25.4F;
                float Height = Bmp.VerticalResolution / 25.4F;