在做report的时候,用到了像素和厘米之间的相互转换
程序是winform 开发
像素转厘米:
/// <summary>
/// 像素转换成厘米
/// </summary>
/// <param name="Pixel">像素</param>
/// <returns>厘米</returns>
private double PixelToCm(double Pixel)
{
double cm = -1;
using (Graphics g = this.CreateGraphics())
{
cm = (Pixel / g.DpiY) * 2.54d;
}
return (double)cm;
}
厘米转像素
private int CentimeterToPixel(double Centimeter)
{
double pixel = -1;
using (Graphics g = this.CreateGraphics())
{
pixel = Centimeter * g.DpiY / 2.54d;
}
return (int)pixel;
}