vc6中怎样显示JPG图片?

blackb 2004-07-27 03:50:49
我用"kodak图象编辑控件", 可以显示,但图片显示质量很差!
请问各位是怎么显示图片的?
...全文
592 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
gwinner 2005-05-31
  • 打赏
  • 举报
回复
显示有很多方法,不过要兼顾到速度和图片质量,可能就复杂一些。

我个人现在在用GDI+,下面是从buffer里拿JPEG的代码,如果你从文件里取,就自己做一下相应改动:
void
CVideoWnd::DrawJPEG(BYTE * pData, DWORD wDataLen)
{
IPicture * pPic = NULL;
IStream * pStream = NULL;

HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, wDataLen);
if (hGlobal != NULL)
{
LPVOID pvData = GlobalLock(hGlobal);
if ((pvData) != NULL)
{
memcpy(pvData, pData, wDataLen);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);

Graphics graphics(m_pDC->m_hDC);
Image imgJpeg(pStream);

Point destPoints[3] = {Point(0, 0), Point(imgJpeg.GetWidth(), 0), Point(0, imgJpeg.GetHeight()) };
// Point destPoints[3] = {Point(0, 0), Point(720, 0), Point(0, 480) };
graphics.DrawImage(&imgJpeg, destPoints, 3); // TODO: add draw code for native data here
}
pStream->Release();
}
}

如果你不太清楚怎样使用GDI+,请参考:
如果你使用的是VC6,请先安装Visual SDK.

1. 在你放置以上函数的文件开始:
using namespace Gdiplus;
2. 定义全局或类成员:GdiplusStartupInput gdiplusStartupInput;
3. 在你的程序入口加入:
ULONG_PTR gdiplusToken;

GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
4. 在程序退出时:
GdiplusShutdown(gdiplusToken);
langzihuitou 2005-05-31
  • 打赏
  • 举报
回复
CClientDC dc(this);
CPictureHolder hd;
HRESULT hr = ::OleLoadPicturePath(CComBSTR("e:\\1.jpg"),NULL,0,0,IID_IPicture,(LPVOID *)&hd.m_pPict);
hd.Render(&dc,CRect(0,0,200,200),CRect(0,0,200,200));

但是需要文件头文件包含
#ifndef __AFXCTL_H__
#include <afxctl.h>
#endif
#include <atlbase.h>
醉马不肖 2004-07-28
  • 打赏
  • 举报
回复
IPicture
badboy520 2004-07-28
  • 打赏
  • 举报
回复
hehe ! 有现成的类可以用,为何非的用个控件了!!
MagiSu 2004-07-28
  • 打赏
  • 举报
回复
okay, 我要你写的控件,三楼的。
blackb 2004-07-27
  • 打赏
  • 举报
回复
各位大哥,我用"kodak图象编辑控件"很方便的.下面两句就完成了图象的显示,只是质量不好.
m_Self.SetImage("background.jpg");
m_Self.Display();

你们的办法能具体点说明吗?
dreamy 2004-07-27
  • 打赏
  • 举报
回复
用GdiPlus,方便
Kudeet 2004-07-27
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=192922
hujack 2004-07-27
  • 打赏
  • 举报
回复
我写了一个控件,还不错。如果想要可以联系我。
lixiaosan 2004-07-27
  • 打赏
  • 举报
回复
http://www.codeproject.com/bitmap/cximage.asp

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧