故障:
ScreenCapture.exe 中的 0x4ed9b280 (GdiPlus.dll) 处最可能的异常: 0xC0000005: 写入位置 0x015a0013 时发生访问冲突
ScreenCapture.exe 中的 0x4ed9b280 (GdiPlus.dll) 处最可能的异常: 0xC0000005: 写入位置 0x015a1034 时发生访问冲突
分析:
我已经初始化了GDI+了,每次当我DrawImage或者Save图片的时候就抛出异常,但是,DrawImage能正常显示图像,Save也能保存图像。任务管理器里也没出现内存泄露阿,资源泄露阿!系统抛出异常严重影响性能阿,这个问题大家遇到过吗?
希望有高手解答!这里我也看到同样的问题了,但是没解决
http://topic.csdn.net/u/20090114/18/07ac1cb8-d5c1-4845-b947-d95d2047b08a.html
ScreenCapture.exe 中的 0x4ed9b280 (GdiPlus.dll) 处最可能的异常: 0xC0000005: 写入位置 0x015a0013 时发生访问冲突
ScreenCapture.exe 中的 0x4ed9b280 (GdiPlus.dll) 处最可能的异常: 0xC0000005: 写入位置 0x015a1034 时发生访问冲突
分析:
我已经初始化了GDI+了,每次当我DrawImage或者Save图片的时候就抛出异常,但是,DrawImage能正常显示图像,Save也能保存图像。任务管理器里也没出现内存泄露阿,资源泄露阿!系统抛出异常严重影响性能阿,这个问题大家遇到过吗?
希望有高手解答!这里我也看到同样的问题了,但是没解决
http://topic.csdn.net/u/20090114/18/07ac1cb8-d5c1-4845-b947-d95d2047b08a.html
[email protected]
{
CDC srcDC, memDC;
CBitmap memBitmap, *pOldBitmap; // 创建屏幕DC
srcDC.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
// 创建内存DC
memDC.CreateCompatibleDC(&srcDC); // 创建内存图像
memBitmap.CreateCompatibleBitmap(&srcDC, m_rcRect.Width(), m_rcRect.Height());
pOldBitmap = memDC.SelectObject(&memBitmap);
memDC.BitBlt(0, 0, m_rcRect.Width(), m_rcRect.Height(), &srcDC, m_rcRect.left, m_rcRect.top, SRCCOPY);
// 获取图像信息
CLSID encoderClsid;
Status stat; BITMAP bmpInfo = {0};
memBitmap.GetBitmap(&bmpInfo);
Bitmap bmp((HBITMAP)memBitmap.m_hObject, NULL); // 释放资源
memDC.SelectObject(pOldBitmap);
memDC.DeleteDC();
srcDC.DeleteDC(); void *pBuf = NULL;
size_t size;
GdiPlusHelper::ImageToMemory(&bmp, &pBuf, &size, L"image/gif");
Image *pImage = NULL;
pImage = GdiPlusHelper::ImageFromMemory(pBuf, size);
// 设置保存图像格式
GdiPlusHelper::GetEncoderClsid(L"image/gif", &encoderClsid);
// 保存
//stat = pImage->Save(L"test.gif", &encoderClsid, NULL); delete pImage;
free(pBuf);
return true;
/*if( stat == Ok )
{
TRACE(_T("saved successfully\n"));
return true;
}
else
{
TRACE1("Failure: stat = %d\n", stat);
return false;
}*/
}
GetClientRect(rcClient); Graphics graph(dc); Bitmap bmp(_T("test.gif")); graph.DrawImage(&bmp, 0, 0, rcClient.Width(), rcClient.Height());
First-chance exception in ScreenCapture.exe (GDIPLUS.DLL): 0xC0000005: Access Violation
也会抛出异常?test.gif是在_CaptureSave函数中保存的吧?
感觉应该是test.gif文件头,或图像头有错误导致。
原因可能应该是在memBitmap.GetBitmap(&bmpInfo);获取的bmpInfo信息内部参数有冲突。仅仅是猜疑~~
{
return NULL;
}出现了kernel异常@!也同样可以运行出结果
第一个参数不管有无,都会出现异常!
而我保存为gif的话,CreateStreamOnHGlobal不会出现异常,GDIPLUS内部会抛异常了
Graphics *gdiDC = Graphics::FromHWND(m_hWnd);
gdiDC->DrawImage(pBitmap,0,0);
delete pBitmap;
delete gdiDC;
也可以这样
CDC *pDC = GetDC();
Graphics gdiDC(pDC->GetSafeHdc());
ReleaseDC(pDC);
问题可能出在这,pEncoderParameters的设置方法决定结果,
建议LZ查看一下gif的设置方法;只做过bmp和jpg,链接如下:
http://hi.baidu.com/codeworkman/blog/item/d3b3a3318c74b190a9018e83.html
而我保存为gif的话,CreateStreamOnHGlobal不会出现异常,GDIPLUS内部会抛异常了
memBitmap.GetBitmap(&bmpInfo);
Bitmap bmp((HBITMAP)memBitmap.m_hObject, NULL); // 这个调用的是不是太早了点,会不会影响bmp数据?
memDC.SelectObject(pOldBitmap);
memDC.DeleteDC();
srcDC.DeleteDC();
我试了把释放资源在该函数结束,依然会出现
First-chance exception in ScreenCapture.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
__in HGLOBAL hGlobal,
__in BOOL fDeleteOnRelease,
__out LPSTREAM* ppstm
);Parameters
hGlobal
The memory handle allocated by the GlobalAlloc function. The handle must be allocated as movable and nondiscardable. If the handle is shared between processes, it must also be allocated as shared. New handles should be allocated with a size of zero. If hGlobal is NULL, the CreateStreamOnHGlobal function internally allocates a new shared memory block of size zero.fDeleteOnRelease
A value that indicates whether the underlying handle for this stream object should be automatically freed when the stream object is released. If set to FALSE, the caller must free the hGlobal after the final release. If set to TRUE, the final release will automatically free the hGlobal parameter.而你的hGlobal是没有的,他也去freeppstm
The address of IStream* pointer variable that receives the interface pointer to the new stream object. Its value cannot be NULL.
我加了HGlobal后,也同样抛异常!
1. 第一个参数不能为空
必须使用GlobalAlloc分配
Memory handle allocated by the GlobalAlloc function.
而是在使用stream变量时才会抛出异常。楼主设置断点试一试
注意The handle must be allocated as movable and nondiscardable.
http://topic.csdn.net/u/20090118/18/0c0a1f82-8081-4c16-97b0-212ad0d0bd7a.html