IPicture
IPicture
keywords:IPicture,COM
abstract:IPicture接口应注意的几个问题
打开文件的类型
可以打开(.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
图片的长度单位
图片的长宽单位是“百分之一毫米” ( nWidth / 100 = xxx 毫米 )
x y轴方向
x y轴方向如图(GDI默认y轴向下)
y ^ | +-------------+ | width | | |height | Picture | | | --+-------------+--> |(0,0) x
单位转换
转成像素单位 dc.GetDeviceCaps(LOGPIXELSX) * nWidth/100/25.4
代码示例
OLE_XSIZE_HIMETRIC nWidth; OLE_YSIZE_HIMETRIC nHeight; m_spPic->get_Width(&nWidth); m_spPic->get_Height(&nHeight); CClientDC dc(this); int nWidthPix = dc.GetDeviceCaps(LOGPIXELSX)*nWidth/2540.0;//换算成像素 int nHeightPix = dc.GetDeviceCaps(LOGPIXELSY)*nHeight/2540.0; CRect rc; GetDlgItem(IDC_STC_PIC)->GetWindowRect(&rc); ScreenToClient(&rc); LONG ox = rc.left + rc.Width()/2 - nWidthPix/2; LONG oy = rc.top + rc.Height()/2 - nHeightPix/2; CRect rc2(ox, oy, ox+nWidthPix, oy+nHeightPix); m_spPic->Render(dc.m_hDC, ox, oy, nWidthPix, nHeightPix, 0, nHeight, nWidth, -nHeight, &rc2);