Excel row of high pixel values, the transition between the pixel values of column width, pixel painting drawn Excel.

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/chenxiaotao22/article/details/101358737
private static float GetDpiX()
{
    try
    {
        using (Bitmap image = new Bitmap(1, 1))
        {
            using (Graphics graphics = Graphics.FromImage(image))
            {
                return graphics.DpiX;
            }
        }
    }
    catch
    {
        return 72;
    }
}

Incoming pixel numPixel

int numPixel = (int)numericUpDown1.Value;
Bitmap image = ConvertToFormat(fileImage.Image, PixelFormat.Format24bppRgb);
//Bitmap image = (Bitmap)fileImage.Image;
g = pictureBox1.CreateGraphics();


double rowHeight = (double)((float)numPixel * 72f / (float)GetDpiX());
                 
for (int i = 0; i < 100; i++)
{


    double colWidth = Math.Round((numPixel < 12 ? (numPixel / 12.00) : (1 + ((numPixel - 12) / 7.00))), 2);
    int _numPixel = (int)Math.Round(colWidth < 1 ? colWidth * 12.0 : 12 + (colWidth - 1) * 7.00); 
    Console.WriteLine(string.Format($"{numPixel}  {colWidth}   {_numPixel}"));
    numPixel = numPixel + 1;
    //double width = (double)((float)numPixel * 72f / (float)GetDpiX());
}

 100 prints out the comparison which excel

 

1 0.08
2 0.17
3 0.25
4 0.33
5 0.42
6 0.5
7 0.58
8 0.67
9 0.75
10 0.83
11 0.92
12 1
13 1.14
14 1.29
15 1.43
16 1.57
17 1.71
18 1.86
19 2
20 2.14
21 2.29
22 2.43
23 2.57
24 2.71
25 2.86
26 3
27 3.14
28 3.29
29 3.43
30 3.57
31 3.71
32 3.86
33 4
34 4.14
35 4.29
36 4.43
37 4.57
38 4.71
39 4.86
40 5
41 5.14
42 5.29
43 5.43
44 5.57
45 5.71
46 5.86
47 6
48 6.14
49 6.29
50 6.43
51 6.57
52 6.71
53 6.86
54 7
55 7.14
56 7.29
57 7.43
58 7.57
59 7.71
60 7.86
61 8
62 8.14
63 8.29
64 8.43
65 8.57
66 8.71
67 8.86
68 9
69 9.14
70 9.29
71 9.43
72 9.57
73 9.71
74 9.86
75 10
76 10.14
77 10.29
78 10.43
79 10.57
80 10.71
81 10.86
82 11
83 11.14
84 11.29
85 11.43
86 11.57
87 11.71
88 11.86
89 12
90 12.14
91 12.29
92 12.43
93 12.57
94 12.71
95 12.86
96 13
97 13.14
98 13.29
99 13.43
100 13.57

Guess you like

Origin blog.csdn.net/chenxiaotao22/article/details/101358737