关于gdi+中image.save的问题!

xinglsm 2008-11-10 04:39:41
Bitmap bmp(pdlg->CatchScreen(rc),0);
img = bmp.GetThumbnailImage(bmp.GetWidth(),bmp.GetHeight());
if (!pdlg->GetImageCLSID(L"image/jpeg",&clsid))
{
AfxMessageBox("clsid error!");
return;
}
name.Format("g:/temp%d.jpg",index);
Status sta = img->Save(name.AllocSysString(),&clsid);
有段代码是这样的,拷全屏,然后转为JPG保存在文件中,
但不知道为什么循环执行到第二十六次的时候就会出错,sta= InvalidParameter;
请高手帮忙解决一下!一到二十五次很正常很顺利的!
...全文
439 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaopoy 2008-11-12
  • 打赏
  • 举报
回复
入的参
一直是全屏rect?
well,计数缓冲区溢出冲了rc参数?那可真想象力太丰富了。

觉得该是
nWidth, nHeight出问题了。
星羽 2008-11-11
  • 打赏
  • 举报
回复
name.Format("g:/temp%d.jpg",index);

->

name.Format("g:\\temp%d.jpg",index);

??
xinglsm 2008-11-11
  • 打赏
  • 举报
回复
HBITMAP CatchScreen(CRect cr)
{
HDC hScrDC, hMemDC;
// 屏幕和内存设备描述表
HBITMAP hBitmap, hOldBitmap;
// 位图句柄
int nX, nY, nX2, nY2;
// 选定区域坐标
int nWidth, nHeight;

// 确保选定区域不为空矩形
if (IsRectEmpty(cr))
return NULL;
//为屏幕创建设备描述表
hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);

//为屏幕设备描述表创建兼容的内存设备描述表
hMemDC = CreateCompatibleDC(hScrDC);
// 获得选定区域坐标
nX = cr.left;
nY = cr.top;
nX2 = cr.right;
nY2 = cr.bottom;

//确保选定区域是可见的
if (nX < 0)
nX = 0;
if (nY < 0)
nY = 0;
if (nX2 > m_xScreen)
nX2 = m_xScreen;
if (nY2 > m_yScreen)
nY2 = m_yScreen;
nWidth = nX2 - nX;
nHeight = nY2 - nY;
// 创建一个与屏幕设备描述表兼容的位图
hBitmap = CreateCompatibleBitmap
(hScrDC, nWidth, nHeight);

// 把新位图选到内存设备描述表中
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
// 把屏幕设备描述表拷贝到内存设备描述表中

BitBlt(hMemDC, 0, 0, nWidth, nHeight,
hScrDC, nX, nY, SRCCOPY);

hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
//得到屏幕位图的句柄
//清除
DeleteDC(hScrDC);
DeleteDC(hMemDC);
return hBitmap;
}
以上这段代码全屏下循环执行25次就出错,就是红色部份,hBitmap==00000000
请问高手有什么解决方法!
xiaopoy 2008-11-11
  • 打赏
  • 举报
回复
img->Save(name.AllocSysString(),&clsid);
缓冲区队列满了?hmm

纯帮顶
帅得不敢出门 2008-11-10
  • 打赏
  • 举报
回复
帮顶
太乙 2008-11-10
  • 打赏
  • 举报
回复
up~~~~~

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧