未能加载图像错误代码2
Failed to load image error code 2
我对编程还很陌生,而且我很难理解作为任务一部分提供给我的代码。
我正在尝试使用代码在程序中绘制位图
void Sprite::Draw(Canvas & c)
{
draw_impl(c);
c.DrawBitmap(50, 50, 50, 50, "H:UserDataDesktopArcadeGameArcadeGameImagescircle.bmp", 255, 0, 0);
}
我现在已经更改了它,所以我使用完整路径而不是相对路径。然而,错误仍然存在。
void WinCanvas::DrawBitmap(int x, int y, int w, int h, std::string filename, int r, int g, int b)
{
std::wstring stemp = std::wstring(filename.begin(), filename.end()); // convert to wide string
HBITMAP hBmp = (HBITMAP)LoadImage(NULL, stemp.c_str(), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT);
if( hBmp == NULL )
{
DWORD err = GetLastError();
std::wstring errorMsg = L"Failed to LoadImage - '" + stemp + L"', error code (" + std::to_wstring((long long)err) + L")";
MessageBox(NULL, errorMsg.c_str(), L"WinCanvas::DrawBitmap()", MB_OK);
PostMessage(m_hWnd, WM_DESTROY, NULL, NULL); // Post a message to destroy (shutdown) the program
return;
.
}
我不确定我的图像位置源是否有问题,或者我是否没有使用正确的整数正确绘制位图。
以下是使用的整数声明
virtual void DrawBitmap(int x, int y, int w, int h, std::string filename, int r=0, int g=0, int b=0);
谢谢你们的帮助。我把代码改成
c.DrawBitmap(50, 50, 50, 50, "H:\UserData\Desktop\ArcadeGame\ArcadeGame\Images\circle.bmp", 255, 0, 0);
然而,它现在出现的错误代码是0,而不是2。如果我读对了,错误消息是说无法加载字符串的字符。
错误代码2:ERROR_FILE_NOT_FOUND. 2 (0x2). The system cannot find the file specified.
- 确保文件存在
- 在路径字符串中使用双斜杠,否则将转义下一个字符,类似于:"H:\\UserData\\Desktop\\ArcadeGame\\ArcadeGame\\Images\\circle.bmp"
相关文章:
- 错误处理.将系统错误代码映射到泛型
- 为什么我在使用void函数时得到错误代码C2276
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 逻辑运算符上出现错误代码 a')'
- 'val' Arduino 错误代码之前的预期'('
- 我在贪吃蛇游戏中收到了错误代码 -1073741571
- 根据 GetLastError 直接写入磁盘会导致错误代码 5
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- 创建进程 API 失败,在窗口 122 上出现错误代码 10
- 使用另一个函数调用一个函数(都在类中)时出现问题.没有错误代码C++
- 当命令失败时,gzip 会在 C++ 中返回错误代码吗?
- 从 C++ 调用 cURL 命令会返回意外的错误代码,如 1792 和 6656
- WSALookupServiceBegin() 上的错误代码 10022(无效的 arugment)
- C++ Schannel POST 400 错误代码错误请求
- openCL-创建子缓冲区返回错误代码13
- 更新了Runge-Kutta(RK4)C++错误代码中的二阶DE
- 获取有关使用未初始化内存的错误代码
- 排序程序的意外错误代码
- 正在将DJI错误代码记录到流中
- 未能加载图像错误代码2