vs2005 MFC 中使用GDI+ 的texturebrush纹理消失
请教大虾:
我在vs2005 MFC 中使用GDI+ 的texturebrush绘制纹理图案,依照宝典http://blog.csdn.net/gavin710/article/details/7362652一步一步做,做成了。
但是发现一个问题:
就是每次程序保存一些图片的参数(高宽,显示位置等)后,texturebrush好像变成透明的了,一下子消失看不到了....
自己debug发现:
1.所用到的其他resource都完好无损;
2.本来保存操作也没对resource作任何更改;
3.而且texturebrush和Graphics都是每次画图都重新创建的,不会受到drawTexture函数外部的影响....
代码如下:
- C/C++ code
void Drawer::drawTexture(CDC &memdc, Image *ibmp, GraphicsPath* mpath){ if(ibmp!=NULL) { // get texture brush TextureBrush tb(ibmp); // get width and hight int w=ibmp->GetWidth(); int h=ibmp->GetHeight(); Graphics mgraphics( memdc.m_hDC); // 每当程序初次运行的时候能正常显示一个填充纹理的椭圆, // 但是只要程序执行一次save操作后就再也看不到纹理图案了。 mgraphics.FillEllipse(&tb,200,0,100,200); // wy为当前图片的宽和高, // 为了验证texturebrush所用的image是否出错而加入的验证代码, // 这里始终能正常显示所用到的纹理图片。 mgraphics.DrawImage(ibmp,RectF(-w/2,-h/2,w,h),0,0,w,h,UnitPixel); // release resources mgraphics.ReleaseHDC(memdc.m_hDC); }}bow~~
[解决办法]
gdi+有个错误检测的函数
GetLastStatus()
你一段一段的调试
你会跟出来的
GDI+编程指南上面写得很清楚