vc6.0下怎样打开jpg格式的图片 看了很多方法 没成功一个 大部分用CImage这个类 但是需要一个动态库 我没有 请问谁有可以发给我一个或者有别的方法吗 谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用下面的代码也可以:::CoInitialize(NULL); // COM 初始化 HRESULT hr; CFile file; file.Open( "c:\\aa.jpg", CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容 DWORD dwSize = file.GetLength(); HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize ); LPVOID lpBuf = ::GlobalLock( hMem ); file.ReadHuge( lpBuf, dwSize ); file.Close(); ::GlobalUnlock( hMem ); IStream * pStream = NULL; IPicture * pPicture = NULL; // 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存 hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream ); ASSERT ( SUCCEEDED(hr) ); hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture ); ASSERT(hr==S_OK); long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米 pPicture->get_Width( &nWidth ); // 宽 pPicture->get_Height( &nHeight ); // 高 ////////原大显示////// CSize sz( nWidth, nHeight ); pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位 pPicture->Render(pDC->m_hDC,0,0,sz.cx,sz.cy, 0,nHeight,nWidth,-nHeight,NULL); ////////按窗口尺寸显示////////// CRect rect; GetClientRect(&rect);// pPicture->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(),// 0,nHeight,nWidth,-nHeight,NULL); if ( pPicture ) pPicture->Release();// 释放 IPicture 指针 if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem ::CoUninitialize(); 在MFC程序中显示JPG/GIF图像 http://www.vckbase.com/document/viewdoc/?id=446 2楼那个程序 调试的时候error C2065: 'pDC' : undeclared identifier: error C2227: left of '->HIMETRICtoDP' must point to class/struct/union: error C2227: left of '->m_hDC' must point to class/struct/unionError executing cl.exe.出现这样三个错误 pdc 未定义 我这段代码只是主要的部分,pDC是你要显示的DC指针啊,你要自己去获取啊,比如你将上面的代码放到OnPaint中,那么你可以用CPaintDC dc(this);去获取DC,不过,我有的DC指针,你改一下就行了。 好吧,这段代码,我连DC都取好了,你试试吧;CDC *dc=GetDC(); ::CoInitialize(NULL); // COM 初始化 HRESULT hr; CFile file; file.Open( "c:\\aa.jpg", CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容 DWORD dwSize = file.GetLength(); HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize ); LPVOID lpBuf = ::GlobalLock( hMem ); file.Read( lpBuf, dwSize ); file.Close(); ::GlobalUnlock( hMem ); IStream * pStream = NULL; IPicture * pPicture = NULL; // 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存 hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream ); ASSERT ( SUCCEEDED(hr) ); hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture ); ASSERT(hr==S_OK); long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米 pPicture->get_Width( &nWidth ); // 宽 pPicture->get_Height( &nHeight ); // 高 ////////原大显示////// CSize sz( nWidth, nHeight ); dc->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位 pPicture->Render(dc->m_hDC,0,0,sz.cx,sz.cy,0,nHeight,nWidth,-nHeight,NULL); ////////按窗口尺寸显示//////// // CRect rect; GetClientRect(&rect); // pPicture->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(), // 0,nHeight,nWidth,-nHeight,NULL); if ( pPicture ) pPicture->Release();// 释放 IPicture 指针 if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem ::CoUninitialize(); CDialog::OnPaint(); 出现这样的错误 cannot access protected member declared in class 'CWnd' 请求帮助(紧急) 如何实现MP3 文件编辑,截取/添加等功能 有没有办法获得网页按钮句柄 链接时候的错误 这个函数(inet_ntoa)为什么用不成? 怎么画线 各位,哪有做录屏的程序?? 偶最近做了个表格控件(15000行代码),要进行测试,留下你们的email,我把控件发给你们,只要给出改进意见就有分 -----------有没有人帮我辨析一下这些东东------------------- win7 系统服务编程问题 VC用UNICODE时编码写进注册表的数据是乱码 SAVEAS应该有几个参数
::CoInitialize(NULL); // COM 初始化
HRESULT hr;
CFile file;
file.Open( "c:\\aa.jpg", CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容
DWORD dwSize = file.GetLength();
HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );
LPVOID lpBuf = ::GlobalLock( hMem );
file.ReadHuge( lpBuf, dwSize );
file.Close();
::GlobalUnlock( hMem );
IStream * pStream = NULL;
IPicture * pPicture = NULL;
// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream );
ASSERT ( SUCCEEDED(hr) );
hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
ASSERT(hr==S_OK);
long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米
pPicture->get_Width( &nWidth ); // 宽
pPicture->get_Height( &nHeight ); // 高
////////原大显示//////
CSize sz( nWidth, nHeight );
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
pPicture->Render(pDC->m_hDC,0,0,sz.cx,sz.cy,
0,nHeight,nWidth,-nHeight,NULL);
////////按窗口尺寸显示////////
// CRect rect; GetClientRect(&rect);
// pPicture->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(),
// 0,nHeight,nWidth,-nHeight,NULL);
if ( pPicture ) pPicture->Release();// 释放 IPicture 指针
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem
::CoUninitialize();
http://www.vckbase.com/document/viewdoc/?id=446
: error C2227: left of '->HIMETRICtoDP' must point to class/struct/union
: error C2227: left of '->m_hDC' must point to class/struct/union
Error executing cl.exe.
出现这样三个错误 pdc 未定义
CDC *dc=GetDC();
::CoInitialize(NULL); // COM 初始化
HRESULT hr;
CFile file; file.Open( "c:\\aa.jpg", CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容
DWORD dwSize = file.GetLength();
HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );
LPVOID lpBuf = ::GlobalLock( hMem );
file.Read( lpBuf, dwSize );
file.Close();
::GlobalUnlock( hMem );
IStream * pStream = NULL;
IPicture * pPicture = NULL;
// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream );
ASSERT ( SUCCEEDED(hr) );
hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
ASSERT(hr==S_OK); long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米
pPicture->get_Width( &nWidth ); // 宽
pPicture->get_Height( &nHeight ); // 高 ////////原大显示//////
CSize sz( nWidth, nHeight );
dc->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
pPicture->Render(dc->m_hDC,0,0,sz.cx,sz.cy,0,nHeight,nWidth,-nHeight,NULL); ////////按窗口尺寸显示////////
// CRect rect; GetClientRect(&rect);
// pPicture->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(),
// 0,nHeight,nWidth,-nHeight,NULL);
if ( pPicture ) pPicture->Release();// 释放 IPicture 指针
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem ::CoUninitialize();
CDialog::OnPaint();