?? jpeg.cpp
字號:
void CModem1Dlg::OpenJpg() //通過modem遠程采集圖像
{
CDC *pDC;
IPicture *pPic;
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
unsigned int i,j;
DWORD temp; //雙字節變量
pDC=GetDC();
if (file.Open(filename,CFile::modeRead)&&file.GetStatus(filename,fstatus)&&((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
if ((pvData = GlobalLock(hGlobal)) != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID* )&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth; //寬度
OLE_YSIZE_HIMETRIC hmHeight; //高度
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
if(FAILED(pPic->Render(*pDC,20,26,CIFH,CIFW,0,hmHeight,hmWidth,-hmHeight,NULL)))
AfxMessageBox("Failed To Render The picture!");
for(i=0;i<CIFW;i++)
for(j=0;j<CIFH;j++)
{
temp=pDC->GetPixel(20+j,26+i);
pixel[((CIFW-i-1)*CIFH+j)*3+0]=GetBValue(temp); //象素值
pixel[((CIFW-i-1)*CIFH+j)*3+1]=GetGValue(temp);
pixel[((CIFW-i-1)*CIFH+j)*3+2]=GetRValue(temp);
}
pPic->Release(); //釋放
pic.SetBitmapBits(CIFW*CIFH*3,pixel);
}
else AfxMessageBox("Error Loading Picture From Stream!"); //報錯:不能采集圖形
}
}
}
else AfxMessageBox("Can't Open Image File!"); //報錯:不能打開圖像文件
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -