c++ - 无法在 Microsoft Visual Studio 2017 C++ 项目中在编译时添加和包含资源
问题描述
我正在尝试将图像添加到 C++ 应用程序。在解决方案资源管理器中单击New Item -> Resource
创建的Resource.rc
文件。在Resource View
添加的新资源中,即Bitmap
图像。该resource.h
文件是
#define IDB_BITMAP1 101
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Resource.rc - 相关部分
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENN)LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_INDIA
// Bitmap
IDB_BITMAP1 JPG "Street.jpg"
#endif // English (India) resources
该程序在 IDE 内运行时没有错误。但是当执行build生成的exe时,似乎找不到资源图像文件。我无法在编译时包含资源。
更新
加载图像并生成输出图像的 C++ 示例代码
#include <iostream>
#include "Open_eVision_2_11.h"
using namespace Euresys::Open_eVision_2_11;
using namespace std;
int main(){
EImageBW8 EBW8Image1; // EImageBW8 instance
// Display version - To make sure lib is included properly.
std::cout << "Open eVison Version: " << Easy::GetVersion();
try {
EBW8Image1.Load("Street.jpg");
EasyImage::Threshold(&EBW8Image1, &EBW8Image1, 140);
EBW8Image1.SaveJpeg("output_image.jpg");
std::cout << "\nImage generated!\n";
}catch (const EException&) {
std::cout << "Error: Possibly image not found!\n";
}
}
当程序在 IDE 中执行时,程序会生成输出图像。但是,当使用此链接创建安装程序并使用Visual Studio Installer
和执行它进行安装时,发现资源图像未正确加载。它打印出库版本和捕获部分。这个问题是否与使用的库有关Open_eVision_2_11.h
?
解决方案
推荐阅读
- c - VScode中未定义的引用错误
- dart - Flutter 键盘溢出
- php - 我无法在 PHP 中解析这个 JSON
- selenium - 重新运行的测试方法标记为已跳过
- python - 带有元组值的spark python中的reduceByKey
- java - 带队列的 Java ThreadFactory
- python - 如何添加与 ManyToManyField 相关的另一个字段?
- python - 将 asyncio 与多工人 ProcessPoolExecutor 相结合
- string - 多个空格分隔符拆分字符串
- python - 无法登录在 django admin 后端创建的超级用户