说说你们要显示图片都用什么类

云满笔记 2013-09-23 10:27:55
我现在用的是GDI+ 内存泄漏太厉害了,比如:

Gdiplus::Graphics graphics(m_hWnd); // 用的是WTL,所有这样写
Gdiplus::Image *image = NULL;

image = Gdiplus::Image::FromFile( PathON );
graphics.DrawImage(image, rtPos);

DeleteObject(&graphics); // 这句可有,可没有,照样泄漏
if ( NULL != image ) { delete image;image=NULL; } // 这句可有,可没有,照样泄漏

执行一遍没事,执行次数多了(每隔1秒刷新一次,VS2008SP1),问题就来了,GDI对象一直泄露,让我吐血,微软的东西实在是不大靠谱啊,大家都用什么类来显示图片啊,要支持多种格式,比如png,jpg,gif...,有什么这样的好用强大盛名的类呢?GDI+实在太坑爹了,让人无法忍受!!说是说没有GDI对象泄漏,说是说类是封装好的,不用这样不用那样,可是用过的人都知道,太TM的侧漏了
...全文
141 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2013-09-24
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
请帖主有空通读MSDN2005中的以下内容。 ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.WIN32COM.v10.en/gdicpp/GDIPlus/GDIPlus.htm GDI+ -------------------------------------------------------------------------------- Purpose Microsoft Windows GDI+ is a class-based application programming interface (API) for C/C++ programmers. It enables applications to use graphics and formatted text on both the video display and the printer. Applications based on the Microsoft Win32 API do not access graphics hardware directly. Instead, GDI+ interacts with device drivers on behalf of applications. GDI+ is also supported by Microsoft Win64. Where Applicable GDI+ can be used in all Windows-based applications. GDI+ is new technology that is included in Windows XP and the Windows Server 2003. It is required as a redistributable for applications that run on the Microsoft Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Millennium Edition (Windows Me) operating systems. Developer Audience The GDI+ C++ class-based interface is designed for use by C/C++ programmers. Familiarity with the Windows graphical user interface and message-driven architecture is required. Run-time Requirements Gdiplus.dll is included with Windows XP. For information about which operating systems are required to use a particular class or method, see the More Information section of the documentation for the class or method. GDI+ is available as a redistributable for Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Me. To download the latest redistributable, see http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdkredist.htm . Note If you are redistributing GDI+ to a downlevel platform or a platform that does not ship with that version of GDI+ natively, install Gdiplus.dll in your application directory. This puts it in your address space, but you should use the linker's /BASE option to rebase the Gdiplus.dll to prevent address space conflict. GDI+ Documentation The GDI+ documentation is organized as shown in the following table. Overview General information about GDI+. Using Tasks and examples using GDI+. Reference Documentation of GDI+ C++ class-based API. Related Topics Windows GDI DirectX Windows Image Acquisition OpenGL Windows Multimedia -------------------------------------------------------------------------------- © 2005 Microsoft Corporation. All rights reserved.
请使用GDI+的道友通读以上内容。
云满笔记 2013-09-23
  • 打赏
  • 举报
回复
自己顶一个先 希望大家多多给力啊
云满笔记 2013-09-23
  • 打赏
  • 举报
回复
引用 9 楼 ananluowei 的回复:
初学gdi+ ,gdi没几天 gdi+的bitmap对象还可以啊,支持多种格式。 gdi+的graphics和image似乎不用releaseobject的吧。 创建graphics的对象不应该用hdc的吗? 如下面这样 HDC hdc = GetDC(hWnd); Graphics gs(hdc); ... ReleaseDC(hWnd, hdc);
试试吧
大尾巴猫 2013-09-23
  • 打赏
  • 举报
回复
初学gdi+ ,gdi没几天 gdi+的bitmap对象还可以啊,支持多种格式。 gdi+的graphics和image似乎不用releaseobject的吧。 创建graphics的对象不应该用hdc的吗? 如下面这样 HDC hdc = GetDC(hWnd); Graphics gs(hdc); ... ReleaseDC(hWnd, hdc);
赵4老师 2013-09-23
  • 打赏
  • 举报
回复
请帖主有空通读MSDN2005中的以下内容。 ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.WIN32COM.v10.en/gdicpp/GDIPlus/GDIPlus.htm GDI+ -------------------------------------------------------------------------------- Purpose Microsoft Windows GDI+ is a class-based application programming interface (API) for C/C++ programmers. It enables applications to use graphics and formatted text on both the video display and the printer. Applications based on the Microsoft Win32 API do not access graphics hardware directly. Instead, GDI+ interacts with device drivers on behalf of applications. GDI+ is also supported by Microsoft Win64. Where Applicable GDI+ can be used in all Windows-based applications. GDI+ is new technology that is included in Windows XP and the Windows Server 2003. It is required as a redistributable for applications that run on the Microsoft Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Millennium Edition (Windows Me) operating systems. Developer Audience The GDI+ C++ class-based interface is designed for use by C/C++ programmers. Familiarity with the Windows graphical user interface and message-driven architecture is required. Run-time Requirements Gdiplus.dll is included with Windows XP. For information about which operating systems are required to use a particular class or method, see the More Information section of the documentation for the class or method. GDI+ is available as a redistributable for Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Me. To download the latest redistributable, see http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdkredist.htm . Note If you are redistributing GDI+ to a downlevel platform or a platform that does not ship with that version of GDI+ natively, install Gdiplus.dll in your application directory. This puts it in your address space, but you should use the linker's /BASE option to rebase the Gdiplus.dll to prevent address space conflict. GDI+ Documentation The GDI+ documentation is organized as shown in the following table. Overview General information about GDI+. Using Tasks and examples using GDI+. Reference Documentation of GDI+ C++ class-based API. Related Topics Windows GDI DirectX Windows Image Acquisition OpenGL Windows Multimedia -------------------------------------------------------------------------------- © 2005 Microsoft Corporation. All rights reserved.
赵4老师 2013-09-23
  • 打赏
  • 举报
回复
GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
healer_kx 2013-09-23
  • 打赏
  • 举报
回复
UIImageView
赵4老师 2013-09-23
  • 打赏
  • 举报
回复
GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
赵4老师 2013-09-23
  • 打赏
  • 举报
回复
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.WIN32COM.v10.en/gdicpp/GDIPlus/usingGDIPlus/usingimagesbitmapsandmetafiles/loadinganddisplayingbitmaps.htm Loading and Displaying Bitmaps -------------------------------------------------------------------------------- To display a raster image (bitmap) on the screen, you need an Image object and a Graphics object. Pass the name of a file (or a pointer to a stream) to an Image constructor. After you have created an Image object, pass the address of that Image object to the DrawImage method of a Graphics object. The following example creates an Image object from a JPEG file and then draws the image with its upper-left corner at (60, 10): Image image(L"Grapes.jpg"); graphics.DrawImage(&image, 60, 10); The following illustration shows the image drawn at the specified location. The Image class provides basic methods for loading and displaying raster images and vector images. The Bitmap class, which inherits from the Image class, provides more specialized methods for loading, displaying, and manipulating raster images. For example, you can construct a Bitmap object from an icon handle (HICON). The following example obtains a handle to an icon and then uses that handle to construct a Bitmap object. The code displays the icon by passing the address of the Bitmap object to the DrawImage method of a Graphics object. HICON hIcon = LoadIcon(NULL, IDI_APPLICATION); Bitmap bitmap(hIcon); graphics.DrawImage(&bitmap, 10, 10); -------------------------------------------------------------------------------- © 2005 Microsoft Corporation. All rights reserved. C++语言局部class变量在退出其作用域时会自动调用其析构函数。
赵4老师 2013-09-23
  • 打赏
  • 举报
回复
检查是否资源泄漏的办法之一: 在任务管理器 进程 查看 选择列 里面选择:内存使用、虚拟内存大小、句柄数、线程数、USER对象、GDI对象 让你的程序(进程)不退出,循环执行主流程很多遍,越多越好,比如1000000次甚至无限循环,记录以上各数值,再隔至少一小时,越长越好,比如一个月,再记录以上各数值。如果以上两组数值的差较大或随时间流逝不断增加,则铁定有对应资源的资源泄漏!
千树之影 2013-09-23
  • 打赏
  • 举报
回复
应该是image没有释放的问题。 怎么得到,怎么释放。 你是用 Gdiplus::Image::FromFile( PathON );得到这个指针的,而不是用new,所以释放肯定也是调用GDI的某个函数 ,而不是用delete

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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