Bitmap::fromFile()失败检测

castlater 2009-09-26 03:12:10
刚入行,问一下怎么检测Bitmap::fromFile()的失败,如果文件名不存在的话,返回的Bitmap*又是什么东西,貌似不是NULL,郁闷了....
...全文
243 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fish_gao 2009-09-28
  • 打赏
  • 举报
回复
给你一个小的例子

ULONG_PTR m_gdiplusToken;
BOOL CTestGdipButtonApp::InitInstance()
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

#if _MFC_VER < 0x700
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
#endif

CTestGdipButtonDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

int CTestGdipButtonApp::ExitInstance()
{
Gdiplus::GdiplusShutdown(m_gdiplusToken);

return CWinApp::ExitInstance();
}

引用了Gdiplus命名空间后,可以把 Gdiplus:: 去掉
fish_gao 2009-09-28
  • 打赏
  • 举报
回复
LZ用的是GDI+吧,你没有启动GDI+呢?
使用前GdiplusStartup调用过没有?
youyifang 2009-09-28
  • 打赏
  • 举报
回复
This method returns a pointer to the new Bitmap object.
他返回的是一个new的对象.
lover9 2009-09-28
  • 打赏
  • 举报
回复
VC++这个东西是很麻烦啊
castlater 2009-09-26
  • 打赏
  • 举报
回复

找到了,在此类的父类Image中,有个函数GetLastStatus(),可以查找到最近的一次错误,我郁闷了,干嘛弄的这么麻烦....
百事烟 2009-09-26
  • 打赏
  • 举报
回复
此函数有返回值,检查一下即可

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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