GDI+ 通过图像的分辨率,大小,屏幕的分辨率,来计算图像的大小。
先上图,该图示一只小狗。
可以有这么的一个算式:内存图像的大小/屏幕的大小 = 内存的分辨率/屏幕的分辨率
代码如下:
View Code
1 private void Form1_Paint(object sender, PaintEventArgs e)
2 {
3 var g = e.Graphics;
4 Bitmap bm = new Bitmap("rama.jpg");
5 g.DrawImage(bm, 0, 0);
6
7 Console.WriteLine("display resolution:DPix{0},DpiY{1} ",g.DpiX,g.DpiY);
8 Console.WriteLine("image resolution:DPix{0},DpiY{1} ",bm.HorizontalResolution,bm.VerticalResolution);
9 Console.Write("image_width:{0}", bm.Width);
10 Console.Write("image_height:{0}",bm.Height);
11 Console.WriteLine("屏幕显示的实际宽度:width{0},height{1}",bm.Width*(g.DpiX/bm.HorizontalResolution),bm.Height*(g.DpiY/bm.VerticalResolution));
12
13 }
2 {
3 var g = e.Graphics;
4 Bitmap bm = new Bitmap("rama.jpg");
5 g.DrawImage(bm, 0, 0);
6
7 Console.WriteLine("display resolution:DPix{0},DpiY{1} ",g.DpiX,g.DpiY);
8 Console.WriteLine("image resolution:DPix{0},DpiY{1} ",bm.HorizontalResolution,bm.VerticalResolution);
9 Console.Write("image_width:{0}", bm.Width);
10 Console.Write("image_height:{0}",bm.Height);
11 Console.WriteLine("屏幕显示的实际宽度:width{0},height{1}",bm.Width*(g.DpiX/bm.HorizontalResolution),bm.Height*(g.DpiY/bm.VerticalResolution));
12
13 }