怎样用对话框打开24位的位图文件并显示 位图文件一般用LoadImage来装入,而CFileDialog一般只是给出你选的文件名 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void CDemoDlg::OnBtnOpen() { CDC *pDC=GetDC(); BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; CFileDialog dlg(TRUE,"*.bmp","001.bmp",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "BMP Files(dlg*.bmp)|*.bmp||"); CString msg; int iResult; iResult=dlg.DoModal(); if(iResult==IDOK) { CString msg; msg+=dlg.GetFileName(); } CFile *fp; fp=new CFile(); fp->Open(msg,CFile::modeRead); fp->SeekToBegin(); fp->Read(&bmfh,sizeof(bmfh)); fp->Read(&bmih,sizeof(bmih)); RGBTRIPLE * rgb=new RGBTRIPLE[bmih.biWidth*bmih.biHeight]; fp->SeekToBegin(); fp->Seek(54,CFile::begin); fp->Read(rgb,bmih.biWidth*bmih.biHeight*3); } fp->Close(); delete fp; delete rgb;} void CDemoDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } if(!bitmap.m_hObject) return; CRect rct; m_image.GetClientRect(&rct); HDC hDC = pDC->GetSafeHdc(); SetStretchBltMode(hDC,HALFTONE); BITMAPINFO bitmapInfo; bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bitmapInfo.bmiHeader.biWidth = bmp.bmWidth; bitmapInfo.bmiHeader.biHeight = bmp.bmHeight; bitmapInfo.bmiHeader.biPlanes = 1; bitmapInfo.bmiHeader.biBitCount = 24; bitmapInfo.bmiHeader.biCompression = BI_RGB; bitmapInfo.bmiHeader.biClrUsed =0; StretchDIBits(hDC,0,0,rct.Width(),rct.Height(),0,bmp.bmHeight,bmp.bmWidth,-bmp.bmHeight,rgb,&bitmapInfo,DIB_RGB_COLORS,SRCCOPY);} DirectShow实现多路视频采集问题 vc6的ATL库在vs2003中的连接错误? 晕死了~~谁进来帮我呀。。 如何生成*.exe文件 CTreeCtrl能同时选中多项吗? gdi+给代码,求问? 请给一个用API做的socket的Windows程序!100分 在ADO中不使用ODBC数据源如何直接连接SERVER数据库 本人跪求用VC生成PSD文件的方法 怎么才能让一个DialogBar浮动在窗口的任意一处 如何得到DateTimePicker时间!解决既揭贴! 求RGB24转RGB565,不太丢失清晰度的算法
{
CDC *pDC=GetDC(); BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih; CFileDialog dlg(TRUE,"*.bmp","001.bmp",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"BMP Files(dlg*.bmp)|*.bmp||");
CString msg;
int iResult;
iResult=dlg.DoModal();
if(iResult==IDOK)
{
CString msg;
msg+=dlg.GetFileName();
}
CFile *fp;
fp=new CFile();
fp->Open(msg,CFile::modeRead);
fp->SeekToBegin();
fp->Read(&bmfh,sizeof(bmfh));
fp->Read(&bmih,sizeof(bmih)); RGBTRIPLE * rgb=new RGBTRIPLE[bmih.biWidth*bmih.biHeight];
fp->SeekToBegin();
fp->Seek(54,CFile::begin);
fp->Read(rgb,bmih.biWidth*bmih.biHeight*3);
}
fp->Close();
delete fp;
delete rgb;
}
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
if(!bitmap.m_hObject)
return;
CRect rct;
m_image.GetClientRect(&rct);
HDC hDC = pDC->GetSafeHdc();
SetStretchBltMode(hDC,HALFTONE); BITMAPINFO bitmapInfo;
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biWidth = bmp.bmWidth;
bitmapInfo.bmiHeader.biHeight = bmp.bmHeight;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = 24;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biClrUsed =0; StretchDIBits(hDC,0,0,rct.Width(),rct.Height(),0,bmp.bmHeight,bmp.bmWidth,-bmp.bmHeight,rgb,&bitmapInfo,DIB_RGB_COLORS,SRCCOPY);
}