读书人

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

发布时间: 2013-10-02 13:10:38 作者: rapoo

说说你们要显示图片都用什么类
我现在用的是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的侧漏了 GDI+泄漏 GDI+ 显示图片 扩展类 VS2008SP1
[解决办法]
应该是image没有释放的问题。
怎么得到,怎么释放。
你是用 Gdiplus::Image::FromFile( PathON );得到这个指针的,而不是用new,所以释放肯定也是调用GDI的某个函数 ,而不是用delete
[解决办法]
检查是否资源泄漏的办法之一:
在任务管理器 进程 查看 选择列 里面选择:内存使用、虚拟内存大小、句柄数、线程数、USER对象、GDI对象
让你的程序(进程)不退出,循环执行主流程很多遍,越多越好,比如1000000次甚至无限循环,记录以上各数值,再隔至少一小时,越长越好,比如一个月,再记录以上各数值。如果以上两组数值的差较大或随时间流逝不断增加,则铁定有对应资源的资源泄漏!

[解决办法]
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变量在退出其作用域时会自动调用其析构函数。
[解决办法]
UIImageView

读书人网 >C++

热点推荐