我的程序用到了Gdi+,在调试的时候可以看到VS的output窗口有大量以下内容:
First-chance exception at 0x4aee65a7 (GdiPlus.dll) in SkinMgr.exe: 0xC0000005: Access violation writing location 0x014a1044.
直接运行的时候不管是Debug还是Release版都没有问题。
这个问题初步定为在调用Gdiplus::Bitmap::SelectActiveFrame,
网上也没有什么说明方法,只有MS针对2008或者Vista的一个HotFix,但是不能要求用户装这个Hotfix。
开发及运行环境如下:
Windows Xp Sp3
Microsoft Visual Studio 2008 Team Suite
Gdiplus.dll版本:5.2.6001.22319
程序为MFC Application
不知道有没有人遇到过这个问题没有。
问题重现程序代码如下:
int _tmain(int argc, _TCHAR* argv[]) { ULONG_PTR dwToken = 0; Gdiplus::GdiplusStartupInput _input; Gdiplus::GdiplusStartup(&dwToken, &_input, NULL); GUID pageGuid = Gdiplus::FrameDimensionTime; HBITMAP hBitmap[10] = {0}; Bitmap* pBitmap = Bitmap::FromFile(_T("D:\\Projects\\SkinMgr\\Image\\checkingassist.gif")); for(int i=0; i<10; ++ i) { pBitmap->SelectActiveFrame(&pageGuid, i); pBitmap->GetHBITMAP(Color(0, 0, 0, 0), &hBitmap[i]); DeleteObject(hBitmap[i]); } Gdiplus::GdiplusShutdown(dwToken); return 0; }
2011/2/11 hu dot <huha...@gmail.com>:
我的程序用到了Gdi+,在调试的时候可以看到VS的output窗口有大量以下内容:
First-chance exception at 0x4aee65a7 (GdiPlus.dll) in SkinMgr.exe: 0xC0000005: Access violation writing location 0x014a1044.
直接运行的时候不管是Debug还是Release版都没有问题。
这个问题初步定为在调用Gdiplus::Bitmap::SelectActiveFrame,
网上也没有什么说明方法,只有MS针对2008或者Vista的一个HotFix,但是不能要求用户装这个Hotfix。
开发及运行环境如下:
Windows Xp Sp3
Microsoft Visual Studio 2008 Team Suite
Gdiplus.dll版本:5.2.6001.22319
程序为MFC Application
2011/2/11 hu dot <huha...@gmail.com>:
> stackoverflow
SelectActiveFrame问题如何解决?
http://topic.csdn.net/u/20090824/17/01be9af4-f62c-4ff0-a5a5-27599f3818ab.html
http://topic.csdn.net/u/20090114/18/07ac1cb8-d5c1-4845-b947-d95d2047b08a.html
http://dotnet.itags.org/dotnet-tech/73250/
This does look like a bug in GDI+. The problem is with the interaction
between the ImageAttributes and the active frame. It appears that any
changes to the ImageAttributes cause the DrawImage() call to use frame 0.
So, one workaround would be to not use the DrawImage() call which uses
ImageAttributes. Another, as you've noted, would be to extract the frame
into another Bitmap and use that instead.
上面提到的,不使用ImageAttributes,我试验了一下,不行。至于说,先解码GIF的帧到新的Bitmap,从而绕过SelectActiveFrame,我想应该是可以的,但是,这会直接导致内存耗用过多!一幅二十帧、160×120的GIF动画,解码到新的Bitmap,需要耗用20×160×120×32/8=约1.5MB内存,这显然是没法接受的。
这个问题也只能是保留。后面可能采用IPicture接口代替GDI+的Gif动画接口。