这是我写的一段代码,用gdi+来把jpg转成bmp,但每次执行以后就会多占用2到3m内存无法释放.请问应如何处理
-------------------------------------------------
HDC m_hdc = GetDC(hwnd);
HDC m_hdcmem = CreateCompatibleDC(m_hdc);
HWND m_hwnd = hwnd;
int i = ReleaseDC(hwnd,m_hdc);
if(m_hdc == NULL) return;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Graphics graphics(m_hdcmem); Image image(ToWChar(strFileName.GetBuffer(strFileName.GetLength())));
CLSID clsid;
if(GetImageCLSID(L"image/bmp", &clsid))
image.Save(ToWChar(".\\test.bmp"), &clsid, NULL);
HBITMAP hbmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(),".\\test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
BITMAP bm;
GetObject(hbmp, sizeof(bm), &bm);
SelectObject(m_hdcmem,hbmp);
DelPointFile("test.bmp",".");-------------------------------------------
注:GdiplusShutedown是在后面处理的.hwnd由外部传入,DelPointFile是用来删除文件的函数
-------------------------------------------------
HDC m_hdc = GetDC(hwnd);
HDC m_hdcmem = CreateCompatibleDC(m_hdc);
HWND m_hwnd = hwnd;
int i = ReleaseDC(hwnd,m_hdc);
if(m_hdc == NULL) return;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Graphics graphics(m_hdcmem); Image image(ToWChar(strFileName.GetBuffer(strFileName.GetLength())));
CLSID clsid;
if(GetImageCLSID(L"image/bmp", &clsid))
image.Save(ToWChar(".\\test.bmp"), &clsid, NULL);
HBITMAP hbmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(),".\\test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
BITMAP bm;
GetObject(hbmp, sizeof(bm), &bm);
SelectObject(m_hdcmem,hbmp);
DelPointFile("test.bmp",".");-------------------------------------------
注:GdiplusShutedown是在后面处理的.hwnd由外部传入,DelPointFile是用来删除文件的函数
解决方案 »
- 有什么函数能把数字转成ASCII呢?
- 我想学使用http和ftp协议下载文件,哪有资料参考一下啊?
- 只使用 smart 指针的情况下,怎么样显示一个activex的界面呢?
- 上下文菜单的菜单资源无法通过可视化添加吗?就想窗口菜单一样?
- 今天一天了,我实在没办法了,进来求个答案,怎么判断文件为视频还是音频文件,望大侠相助!
- 哪个高人能说说关于image和map??关于PE文件弄到内存前后,什么什么的~
- (up有分!)运行程序提示:"ODBC cannot load the resource\动态创建dsn\MyApp\Debug\"???
- 谁知道visio 2002的注册吗?谢谢!
- 请问在mfc的mdi工程中如何不让程序自动生成子窗口?
- MFC事件处理--电机运动控制
- 高手请进,在一个类中不能添加另一个类的类型变量...先答先得.
- 请教怎样用VC++6.0访问SQL SERVER 2000数据库?
Require your clients to call GdiplusStartup before they call the functions in your DLL and to call GdiplusShutdown when they have finished using your DLL.
Export your own startup function that calls GdiplusStartup and your own shutdown function that calls GdiplusShutdown. Require your clients to call your startup function before they call other functions in your DLL and to call your shutdown function when they have finished using your DLL.
Call GdiplusStartup and GdiplusShutdown in each of your functions that make GDI+ calls.
release(m_hdc);
release(m_hdcmem);
releaseDC(hdc)..凡是资源 使用后记得释放 ,看次三篇文章
http://www.csdn.net/Develop/Read_Article.asp?Id=22766
http://www.csdn.net/Develop/Read_Article.asp?Id=22767
http://www.csdn.net/Develop/Read_Article.asp?Id=22768
可能调用了多次GdiplusStartup而只调用了一次GdiplusShutdown
hbmp 没有删除
SelectObject返回的对象没有被释放或者重新选择
Image image(ToWChar(strFileName.GetBuffer(strFileName.GetLength())));
CLSID clsid;
if(GetImageCLSID(L"image/bmp", &clsid))
image.Save(ToWChar(".\\test.bmp"), &clsid, NULL);
这两句耗掉最多内存,且无法恢复.请问怎样释放image的内存?