计算图片物理大小
2013-09-05 17:04
183 查看
//先计算系统dpi,以下是代码 public partial class Form1 : Form { int dpi_x; int dpi_y; public Form1() { InitializeComponent(); //SetProcessDPIAware(); //重要 IntPtr screenDC = GetDC(IntPtr.Zero); dpi_x = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSX); dpi_y = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSY); // dpi_x = 96.0; // dpi_y = 96.0; ReleaseDC(IntPtr.Zero, screenDC); } [DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr ptr); [DllImport("user32.dll", EntryPoint = "ReleaseDC")] public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc); [DllImport("gdi32.dll")] public static extern IntPtr CreateDC( string lpszDriver, // driver name string lpszDevice, // device name string lpszOutput, // not used; should be NULL Int64 lpInitData // optional printer data ); [DllImport("gdi32.dll")] public static extern int GetDeviceCaps( IntPtr hdc, // handle to DC int nIndex // index of capability ); [DllImport("user32.dll")] internal static extern bool SetProcessDPIAware(); const int DRIVERVERSION = 0; const int TECHNOLOGY = 2; const int HORZSIZE = 4; const int VERTSIZE = 6; const int HORZRES = 8; const int VERTRES = 10; const int BITSPIXEL = 12; const int PLANES = 14; const int NUMBRUSHES = 16; const int NUMPENS = 18; const int NUMMARKERS = 20; const int NUMFONTS = 22; const int NUMCOLORS = 24; const int PDEVICESIZE = 26; const int CURVECAPS = 28; const int LINECAPS = 30; const int POLYGONALCAPS = 32; const int TEXTCAPS = 34; const int CLIPCAPS = 36; const int RASTERCAPS = 38; const int ASPECTX = 40; const int ASPECTY = 42; const int ASPECTXY = 44; const int SHADEBLENDCAPS = 45; const int LOGPIXELSX = 88; const int LOGPIXELSY = 90; const int SIZEPALETTE = 104; const int NUMRESERVED = 106; const int COLORRES = 108; const int PHYSICALWIDTH = 110; const int PHYSICALHEIGHT = 111; const int PHYSICALOFFSETX = 112; const int PHYSICALOFFSETY = 113; const int SCALINGFACTORX = 114; const int SCALINGFACTORY = 115; const int VREFRESH = 116; const int DESKTOPVERTRES = 117; const int DESKTOPHORZRES = 118; const int BLTALIGNMENT = 119; private void button1_Click(object sender, EventArgs e) { MessageBox.Show(dpi_x.ToString()+"||"+dpi_y.ToString()); } }
float pw=w/myThumbnail.HorizontalResolution*dpi_x;//物理大小=像素/分辨率*dpi float ph=h/2/myThumbnail.VerticalResolution*dpi_y;
相关文章推荐
- 计算图片大小,如果从内存和本地取不到图片,就去下载,并计算图片大小
- 如何计算初始图片的大小?像素,分辨率
- gridview宽度自适应屏幕间距---计算一个item(或某个图片)的占屏幕大小
- iOS获取网络图片计算其大小
- android 计算Bitmap占byte大小,以及Bitmap中像素数的计算,另外再给出一个按尺寸裁剪图片的方法
- Android不同分辨率图片实际显示大小的计算
- 函数计算-触发OSS来处理图片加水印和大小裁剪
- 计算图片缓存大小
- Android不同分辨率图片实际显示大小的计算
- 优化ImageView,在使用ListView或GridView的时候,每次更新图片的时候,在显示新的图片和旧的图片一样大小的时候,不需要去重新计算大小
- 关于硬盘种类、物理几何结构及硬盘容量、分区大小计算
- 计算文件大小和base64解码图片
- 函数计算-触发OSS来处理图片加水印和大小裁剪
- 图片占用内存大小计算---pvr和png为例子
- Android中一张图片占据的内存大小是如何计算
- iOS 计算SDWebImage本地缓存图片大小+清理本地缓存的图片
- 计算从ios照片库中选取的图片文件大小
- 卷积后的图片大小计算
- Android多媒体编程——图片的大小计算
- asp.net 修改图片的分辨率,修改图片的长宽象素比例,修改图片的物理宽度大小