获取Picture位置及其大小并显示位图
来源:互联网 发布:老男孩知乎 编辑:程序博客网 时间:2024/05/10 13:55
void Student::DrawBMP()
{
// if we don't have an image, get out of here
JpegFile jpg;
if (pRGB==NULL) return;//pRGB图像数据
CDC *theDC = GetDC();
if (theDC!=NULL) {
// a 24-bit DIB is DWORD-aligned, vertically flipped and
// has Red and Blue bytes swapped. we already did the
// RGB->BGR and the flip when we read the images, now do
// the DWORD-align
BYTE *tmp;
// DWORD-align for display
UINT m_widthDW;
tmp = jpg.MakeDwordAlignedBuf(pRGB,
m_nWidth,
m_nHeigth,
&m_widthDW);
// set up a DIB
BITMAPINFOHEADER bmiHeader;
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiHeader.biWidth = m_nWidth;
bmiHeader.biHeight = m_nHeigth;
bmiHeader.biPlanes = 1;
bmiHeader.biBitCount = 24;
bmiHeader.biCompression = BI_RGB;
bmiHeader.biSizeImage = 0;
bmiHeader.biXPelsPerMeter = 0;
bmiHeader.biYPelsPerMeter = 0;
bmiHeader.biClrUsed = 0;
bmiHeader.biClrImportant = 0;
CRect cRect;
// CStatic ctrlStatic;//先将picture控件和 一个CStatic变量进行绑定
//得到控件的客户区
m_ctrlStatic.GetClientRect(&cRect);
cRect.NormalizeRect();//
m_ctrlStatic.ClientToScreen(&cRect);
//转换到屏幕坐标,其后获取正确的Picture区域大小
int rHeight = cRect.Height();
int rWidth = cRect.Width();
//控件屏幕坐标转换到相对于对话框的客户坐标
ScreenToClient(&cRect);
// 之后才能获取准确的 picture控件 与 对话框的相对坐标
int rPhotoLeft= cRect.left;
int rPhotoTop = cRect.top ;
int rPhotoRight = cRect.right;
int rPhotoBottom = cRect.bottom;
// now blast it to the CDC passed in.
// lines returns the number of lines actually displayed
int lines = StretchDIBits(theDC->m_hDC,
rPhotoLeft, rPhotoTop,
rPhotoRight-rPhotoLeft,
rPhotoBottom-rPhotoTop,
0,0,
bmiHeader.biWidth,
bmiHeader.biHeight,
tmp,
(LPBITMAPINFO)&bmiHeader,
DIB_RGB_COLORS,
SRCCOPY);
delete [] tmp;
ReleaseDC(theDC);
}
}
//////////////////////////////////////////////////////////////////////////
如果不绑定Picture控件也可如下:
CWnd* pWnd = GetDlgItem(IDC_PICTURE);
pWnd->GetClientRect(&recrt);//相对控件本身的坐标recrt.left=0;recrt.top=0;
pWnd->GetWindowRect(&rect2);//相对与窗体的坐标
pWnd->MoveWindow(0,0,800,600,1);//设置控件的位置和大小
- 获取Picture位置及其大小并显示位图
- picture control上显示位图
- MFC位图自适应Picture Control控件大小
- Android定位获取经纬度并显示位置
- 在Picture Control控件上显示JPG图片并让图片适应控件的大小
- 获取光标位置 并将其位置映射为上一博客中picture控件的逻辑坐标
- 获取位图属性(大小什么的
- MFC中获取picture控件的大小
- 获取鼠标在Picture控件中的坐标,并显示到对话框的状态栏中
- 获取鼠标在Picture控件中的坐标,并显示到对话框的状态栏中
- 获取鼠标在Picture控件中的坐标,并显示到对话框的状态栏中
- 用CImage在picture控件上显示外部图片,并获取各像素颜色数据
- Android 自定义对话框,可设置大小和显示位置,并设置点击其他位置不消失
- 读取并显示位图文件
- MFC打开并显示位图
- mfc改变picture控件的大小和位置
- Java之获取屏幕大小并将窗口居中显示!...
- wince任意位置显示BMP位图
- test
- 进度条的使用方法ProgressMonitor JProgressBar。
- C# 文件总结
- 感悟
- c# 反射
- 获取Picture位置及其大小并显示位图
- 成事不足,败事有余
- 最初
- windows 2008 iis中使用php
- cygwin下的cygheap:从父进程到子进程的复制
- 动态规划(DP)
- 持续集成案例分析系列(2)——大规模项目团队持续集成实践之一二
- 8皇后问题
- Microsoft Interview