标准固定

1 寸=3.3333333 厘米
1 英寸=2.54 厘米

求计算机显示器PPI?

比如对角线14英寸,不是寸,即2.54*14=35.56cm
按16:9算出宽和高 高(9x)2+宽(16x)2=对角线35.56cm2   算出宽*高:30.99*17.43cm  即30.99/2.54英寸
像素为1920*1080  PPI=1920*2.54/30.99= 约157PPI(pixel per inch)

求一张图片在某分辨率下的实际尺寸?

比如600PPI(pixel per inch 显示器)或DPI(dots per inch 打印机) ,像素为1920*1080,算宽*高各为多少英寸或厘米?

像素为1920*1080,打印机为600dpi
宽=1920/600 英寸=1920/600*2.54 厘米=8.128 厘米
高=1080/600 英寸=1080/600*2.54 厘米=4.572 厘米

现在改为打印机300dpi,要求实际物理尺寸不变。
宽=width/300 英寸=width/300*2.54 厘米=8.128 厘米
高=height/300 英寸=height/300*2.54 厘米=4.572 厘米
必须缩放图片像素为960*540

所以,不同点数的打印机要按实际物理尺寸打印图片,那必须缩放图片,即改变像素。实际尺寸以打印机为600dpi为标准:currnet_x_pix=old_x_pix/600*currnet_dpi

C#按物理尺寸打印图片 e.Graphics.DrawImage(image,0,0); //按物理尺寸打印标签,600点改为300点的打印机_小黄人软件的博客-CSDN博客

MFC按实际物理尺寸打印图片

方法1.获得打印机点数,按点数转换图片像素


#include "pch.h"
#include "../pch.h"
#include "../utility/utility.h"
#include <atlbase.h> using namespace Gdiplus;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{UINT  num = 0;          // number of image encodersUINT  size = 0;         // size of the image encoder array in bytesImageCodecInfo* pImageCodecInfo = NULL;GetImageEncodersSize(&num, &size);if (size == 0)return -1;  // FailurepImageCodecInfo = (ImageCodecInfo*)(malloc(size));if (pImageCodecInfo == NULL)return -1;  // FailureGetImageEncoders(num, size, pImageCodecInfo);for (UINT j = 0; j < num; ++j){if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0){*pClsid = pImageCodecInfo[j].Clsid;free(pImageCodecInfo);return j;  // Success}}free(pImageCodecInfo);return -1;  // Failure
}
BOOL getBMPInfo(LPCTSTR  fileName)
{// Initialize GDI+.GdiplusStartupInput gdiplusStartupInput;ULONG_PTR gdiplusToken;GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);USES_CONVERSION;Gdiplus::Bitmap* pBitmap = new Gdiplus::Bitmap(T2W(fileName));if (pBitmap == NULL || pBitmap->GetLastStatus() != Gdiplus::Ok) { logger.ERROR_F(__FUNCTION__+to_string(__LINE__)+"出错:" + to_string(pBitmap->GetLastStatus()));  delete pBitmap; return FALSE; }logger.INFO_F("水平*垂直分辨率:" +to_string(pBitmap->GetHorizontalResolution()) + "*" + to_string(pBitmap->GetVerticalResolution()));logger.INFO_F("width*height像素:" + to_string(pBitmap->GetWidth())+"*"+ to_string(pBitmap->GetHeight()));logger.INFO_F("600dpi时width*height厘米:" + to_string((float)(pBitmap->GetWidth())*2.54 /600) + "*" + to_string((float)(pBitmap->GetHeight())*2.54 /600));//if (abs(pBitmap->GetHorizontalResolution() - dpi)>0.5 || abs(pBitmap->GetVerticalResolution() - dpi)> 0.5)//{// logger.ERROR_F("水平分辨率" + to_string(pBitmap->GetHorizontalResolution()) + "或垂直分辨率" + to_string(pBitmap->GetVerticalResolution()) + " 错误,应该为" + to_string(dpi));//   delete pBitmap;//   return FALSE;//}delete pBitmap;return TRUE;
}
BOOL setBMPResolution(LPCTSTR  fileName, float dpi)
{LPCTSTR outFileName = "temp.bmp";// Initialize GDI+.GdiplusStartupInput gdiplusStartupInput;ULONG_PTR gdiplusToken;GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);USES_CONVERSION;Gdiplus::Bitmap* pBitmap = new Gdiplus::Bitmap(T2W(fileName));if (pBitmap==NULL || pBitmap->GetLastStatus() != Gdiplus::Ok) { logger.ERROR_F("转分辨率出错:" + to_string(pBitmap->GetLastStatus()));  delete pBitmap;  return FALSE; }Gdiplus::Status status = pBitmap->SetResolution(dpi, dpi);//设置此 Bitmap 的分辨率。if (status != Gdiplus::Ok) { logger.ERROR_F("转分辨率:" + to_string(status));  delete pBitmap;   return FALSE; }CLSID clsid;GetEncoderClsid(L"image/bmp", &clsid);             //Get the encoderstatus = pBitmap->Save(T2W(outFileName), &clsid);//Save the image into physical memoryif (status != Gdiplus::Ok) { logger.ERROR_F("转分辨率后,保存错误:" + to_string(status)); delete pBitmap;   return FALSE; }delete pBitmap;pipe_system("del "+ (CString)fileName+"\n", DELAY); //cmd先删除pipe_system("rename " + (CString)outFileName + " "+ fileName +"\n", DELAY); //cmd重命名为原来的名logger.INFO_F(string(fileName)+"设置分辨率成功:" + to_string(dpi));return TRUE;
}void PrintBitmap(LPCTSTR filename)
{//setBMPResolution(filename, 600);//转为600分辨率getBMPInfo(filename);CPrintDialog printDlg(FALSE);printDlg.GetDefaults(); CDC dc;if (!dc.Attach(printDlg.GetPrinterDC())) {AfxMessageBox(_T("No printer found!")); return;} dc.m_bPrinting = TRUE; DOCINFO di;    // Initialise print document details::ZeroMemory (&di, sizeof (DOCINFO));di.cbSize = sizeof (DOCINFO);di.lpszDocName = filename; //显示在打印列表里的名字BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job // Get the printing extents// and store in the m_rectDraw field of a // CPrintInfo objectCPrintInfo Info;Info.SetMaxPage(1); // just one page //打印机页面的水平和垂直像素int maxw = dc.GetDeviceCaps(HORZRES);int maxh = dc.GetDeviceCaps(VERTRES); //打印机每英寸像素数int cxInch = dc.GetDeviceCaps(LOGPIXELSX);int cyInch = dc.GetDeviceCaps(LOGPIXELSY);logger.INFO_F("页面:" + to_string(maxw)+"*"+to_string(maxh) + " 打印机DPI:" + to_string(cxInch)+"*"+to_string(cyInch)); //mm 纸尺寸  Info.m_rectDraw.SetRect(0, 0, maxw, maxh);for (UINT page = Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK; page++) {dc.StartPage();    // begin new pageInfo.m_nCurPage = page;CBitmap bitmap;// LoadImage does the trick here, it creates a DIB section// You can also use a resource here// by using MAKEINTRESOURCE() ... etc. if(!bitmap.Attach(::LoadImage(::GetModuleHandle(NULL), filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE))) {AfxMessageBox(_T("Error loading bitmap!")); return;} BITMAP bm;bitmap.GetBitmap(&bm);//获得宽与高// create memory device contextCDC memDC; memDC.CreateCompatibleDC(&dc);CBitmap *pBmp = memDC.SelectObject(&bitmap);memDC.SetMapMode(dc.GetMapMode());dc.StretchBlt(0, 0, bm.bmWidth * cxInch / 600 , bm.bmHeight * cyInch / 600 , &memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);//按600dpi时的实际尺寸打印//dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &memDC, 0, 0, SRCCOPY); //按图片大小打印// clean upmemDC.SelectObject(pBmp);bPrintingOK = (dc.EndPage() > 0);   // end page} if (bPrintingOK)dc.EndDoc(); // end a print jobelse dc.AbortDoc();           // abort job.
}

DPI(dots per inch) PPI(pixel per inch) 求一张图片在某分辨率下的实际尺寸?求计算机显示器PPI? MFC按600dpi时的实际物理尺寸打印图片相关推荐

  1. 分辨率PPI(Pixel Per Inch)与DPI(Dot Per Inch)

    分辨率PPI与DPI,关于这个问题,现在很多人容易混淆,现摘录几份资料. 图像分辨率所使用的单位是PPI(Pixel Per Inch),意思是:在图像中每英寸所表达的像素数目.从输出设备(如打印机) ...

  2. 图片尺寸像素点,图片的大小,分辨率,a4纸,dpi,ppi,pt,pixel像素,屏幕尺寸

    catalog 图片大小 a4纸 DPI,PPI Pt,Px 图片大小 对于RGB模式, 一个像素点, 由 (R, G, B) 三个 颜色通道 组成; 且, 每个通道, 都占 1个字节; color: ...

  3. Windows下用Python获取电脑显示器物理尺寸和PPI

    Windows下用Python获取电脑显示器物理尺寸和PPI 背景 PPI 和 DPI Python获取PPI 方法一(WMI) 方法二(WINREG) 方法三(WMI+WINREG) 总结 背景 最 ...

  4. 字体号数与像素对应关系

    标准固定 1 英寸=25.4 毫米 1 寸=33.3333333 毫米 1点(英美点)(PT)(磅)=0.3527毫米=1/72英寸(Office里面的点) 字体号数与像素对应关系 Word默认的图片 ...

  5. screen ruler屏幕电子尺源码C# 手机与windows

    标准PPI:72PPI,100%缩放 非标准PPI需要设置一下校准:比如我的约157.3668925459825750242013552759PPI,150%缩放 计算: DPI(dots per i ...

  6. java的像素与dpi_对屏幕的理解---分辨率,dpi,ppi,屏幕尺寸,像素 等

    1. 名词理解 屏幕尺寸(screen size) 屏幕尺寸(screen size),是屏幕的对角线长度,一般讲的大小单位都是英寸. DPI (dots per inch) dpi是(英文Dots ...

  7. 图像处理冷知识——dpi和ppi

    DPI(Dots Per Inch,每英寸点数)是一个量度单位,用于点阵数码影像,指每一英寸长度中,取样.可显示或输出点的数目. DPI是打印机.鼠标等设备分辨率的度量单位.是衡量打印机打印精度的主要 ...

  8. dpi和ppi换算_ppi和dpi换算(1ppi等于多少dpi)

    350dpi扫描精度的照片应该是多少象素的 应该如何换算分辨率 分辨率通常表示成每英寸像素(pixel per inch, ppi)和每英寸点(dot per inch, dpi).ppi和dpi经常 ...

  9. 物理像素、CSS像素、dip、dpr、ppi、dpi

    物理像素(physical pixel) 物理像素又被称为设备像素(dp),他是显示设备中一个最微小的物理部件.一个设备的物理像素是固定不变的.每个像素可以根据操作系统设置自己的颜色和亮度.所谓的一倍 ...

最新文章

  1. 越卖越涨?腾讯股票3月后大涨45%,超越“阿里”成中国第一,市值相当于14.3个百度!...
  2. SpringBoot-MyBatis
  3. 安装mysql5.3_源码安装mysql5.3.35
  4. 用C语言实现解析简单配置文件的小工具
  5. python 散点图 不同颜色_python – pandas – 每个点都有不同颜色图例的散点图
  6. python:栈的理解与应用,让你快速入门Python
  7. 用python开发的运维管理系统下载_GitHub - jiegangwu/OPMS_v3: 基于 Python 3.5 + Django 2.0 开发的运维管理系统...
  8. 字节一面,面试官拿System.out.println()考了我半个小时?我懵逼了...
  9. 16qam星座图 matlab,16qam星形和矩形星座图调制解调matlab代码.doc
  10. 游戏加速外挂的原理是什么 ?
  11. 图文详解win7实现局域网共享文件
  12. latex 箭头上带_latex 上下箭头
  13. 制作u盘winpe启动盘_如何制作纯净的系统U盘启动盘
  14. 【毕业设计】指纹识别系统设计与实现 - 单片机 嵌入式 物联网
  15. C++笔记——第一个MFC程序
  16. 道路密度网arcgis
  17. Java逐行读取fasta文件
  18. RIP、OSPF、BGP、动态路由选路协议、自治域AS
  19. R语言ggplot2可视化:使用patchwork包将3个ggplot2可视化结果横向组合(三幅图各占比例为33.3%,加和为100%)
  20. [Layui]主页tab选项卡操作(刷新页面,刷新选项卡,关闭,关闭其他,全部关闭)

热门文章

  1. Grasshopper 二次开发 (C#) Part 3 - Write Simple Plug-in for Grasshopper in Visual Studio
  2. 1扩展组件 --FEBE
  3. 【APIcould】连接手机设备运行调试
  4. python实现--月报和年报
  5. pgsql sql中获取当前时间_PostgreSQL 如何获取当前日期时间及注意事项
  6. parseObject和fromObject的区别
  7. TurboMosaic for Mac如何制作个性化的照片马赛克拼图
  8. iOS 源生推送和极光推送
  9. Python 数据挖掘(三) matplotlib模块 简单使用
  10. BEV+Transformer对无人驾驶硬件体系的巨大改变