VC处理JPG图片 本帖最后由 cg_qiujie 于 2011-04-08 09:33:34 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 关键就是取得像素。可以用OpenCV等来出来 你可以用CXimage直接转换成bmp格式再处理,或者用其他的工具转成bmp的 VS2005 以上用自带的 CImage类就可以了 建议用 CXimage ,很不错的,http://www.codeproject.com/KB/graphics/cximage.aspx vc6 请使用IPicture接口,这个是标准,vc6以上请使用gdi+ http://www.vckbase.com/document/viewdoc/?id=446 上源码吧BOOL DrawRect(CWnd *pWnd, LPCTSTR strPath, CRect &Rect, int nMode ){ ASSERT(IsWindow(pWnd->GetSafeHwnd())); IStream *pStm; CFileStatus fstatus; CFile file; LONG cb; HGLOBAL hGlobal ; CDC *pDC=pWnd->GetDC(); if (file.Open(strPath,CFile::modeRead)&& file.GetStatus(strPath,fstatus)&& ((cb = fstatus.m_size) != -1)) { hGlobal= GlobalAlloc(GMEM_MOVEABLE, cb); LPVOID pvData = NULL; if (hGlobal != NULL) { pvData = GlobalLock(hGlobal); if (pvData != NULL) { file.ReadHuge(pvData, cb); GlobalUnlock(hGlobal); CreateStreamOnHGlobal(hGlobal, TRUE, &pStm); } } } else { return FALSE; } //打开文件结束 try{ IPicture *pPic; 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); DWORD width, height; CSize sz(hmWidth,hmHeight); pDC->HIMETRICtoDP(&sz); switch(nMode) { case BITBLT: width = Rect.Width(); height = Rect.Height(); break; case STRETCH: { width = sz.cx; height = sz.cy; Rect.right = width + Rect.left; Rect.bottom = height + Rect.top; } break; case AUTO: { width = Rect.Width(); height = sz.cy * width / sz.cx ; Rect.right = width + Rect.left; Rect.bottom = height + Rect.top; } } //先将图片画到内存DC中 CDC MemDC; MemDC.CreateCompatibleDC(NULL); CBitmap hbitmap; hbitmap.CreateCompatibleBitmap(pDC, sz.cx, sz.cy); CBitmap *pOldBit = MemDC.SelectObject(&hbitmap); if(FAILED(pPic->Render(MemDC, 0, 0, sz.cx, sz.cy, 0, hmHeight,hmWidth, -hmHeight,NULL))) { pPic->Release(); hbitmap.DeleteObject(); throw(-1); } else { pDC->SetBkMode(TRANSPARENT); pDC->SetStretchBltMode(HALFTONE); pDC->StretchBlt(Rect.left, Rect.top, width,height,&MemDC,0,0,sz.cx,sz.cy,SRCCOPY ); } hbitmap.DeleteObject(); pPic->Release(); } else { throw(0); } } catch(int nErrorCode) { switch(nErrorCode) { case -1: TRACE("Failed to Render!"); break; case 0: TRACE("Failed to LoadPicture!"); break; } GlobalFree(hGlobal); return false; } GlobalFree(hGlobal); return true; } 我使用ms提供的gdi+ 来打开jpg 缩放,以及修改质量. 保存为bmp,jpg,png 用opencv吧,很容易实现,而且有现成的函数可调用,用CxImage也不错,而且它有个demo,你可以看看 按钮上动态添加文字 请问在upd通信中怎么得到客户端的机器名,系统帐户名,网络登陆名,工作组名 关于GraphicsPath的问题 有人帮忙回答下OPenGl实现Nurbs曲面的函数的一个参数的含义吗?谢谢 急,sendmessage 向另外一个进程传递参数 AdLockOptimistic 高手请进,有没有可能实现SendMessage()的超时,就像recv()一样的效果。 问题大求解!!!!! 画直线怎么出现暗点呢? 求 InstallShield 12 序列号一个 VC如何编译成UNICODE格式 文字生成图片
BOOL DrawRect(CWnd *pWnd, LPCTSTR strPath, CRect &Rect, int nMode )
{
ASSERT(IsWindow(pWnd->GetSafeHwnd()));
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
HGLOBAL hGlobal ;
CDC *pDC=pWnd->GetDC();
if (file.Open(strPath,CFile::modeRead)&&
file.GetStatus(strPath,fstatus)&&
((cb = fstatus.m_size) != -1))
{
hGlobal= GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
pvData = GlobalLock(hGlobal);
if (pvData != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
}
}
}
else
{
return FALSE;
} //打开文件结束
try{
IPicture *pPic;
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);
DWORD width, height;
CSize sz(hmWidth,hmHeight);
pDC->HIMETRICtoDP(&sz);
switch(nMode)
{
case BITBLT:
width = Rect.Width();
height = Rect.Height();
break;
case STRETCH:
{
width = sz.cx;
height = sz.cy;
Rect.right = width + Rect.left;
Rect.bottom = height + Rect.top;
}
break;
case AUTO:
{
width = Rect.Width();
height = sz.cy * width / sz.cx ;
Rect.right = width + Rect.left;
Rect.bottom = height + Rect.top;
}
}
//先将图片画到内存DC中
CDC MemDC;
MemDC.CreateCompatibleDC(NULL);
CBitmap hbitmap;
hbitmap.CreateCompatibleBitmap(pDC, sz.cx, sz.cy);
CBitmap *pOldBit = MemDC.SelectObject(&hbitmap);
if(FAILED(pPic->Render(MemDC, 0, 0, sz.cx, sz.cy, 0,
hmHeight,hmWidth, -hmHeight,NULL)))
{
pPic->Release();
hbitmap.DeleteObject();
throw(-1);
}
else
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(Rect.left, Rect.top, width,height,&MemDC,0,0,sz.cx,sz.cy,SRCCOPY );
}
hbitmap.DeleteObject();
pPic->Release();
}
else
{
throw(0);
}
}
catch(int nErrorCode)
{
switch(nErrorCode)
{
case -1:
TRACE("Failed to Render!");
break;
case 0:
TRACE("Failed to LoadPicture!");
break;
} GlobalFree(hGlobal);
return false;
}
GlobalFree(hGlobal);
return true;
}
用CxImage也不错,而且它有个demo,你可以看看