图像加载功能不工作
Image loading function not working
好吧,我一直在做一个项目,遇到了这个问题。当我运行我的程序时,我得到这个消息:
Unhandled exception at 0x76fa15de in programmingproj.exe: 0xC0000005: Access violation reading location 0x00000000.
下面是Visual Studio认为是错误的代码:
float **LoadImg(const char *filename)
{
float **data = { 0 };
char *buf = new char[32];
std::string buf2;
std::ifstream filebuf(filename);
filebuf.getline(buf, 32);
// Reiterate over each pixel, very inefficient, needs to be fixed.
for (int x = 0; x < (IMAGE_SIZE_X - 1); x++)
{
for (int y = 0; y < (IMAGE_SIZE_Y - 1); y++)
{
filebuf.getline(buf, 32);
// Only copy the values.
for (int i = 8; i < 32; i++)
{
if (buf[i] != 't' && buf[i] != ' ')
{
buf2 += buf[i];
}
}
// Set the pixel's value.
data[x][y] = (float)strtodbl(buf2);
}
}
filebuf.close();
return data;
}
下面是我正在尝试阅读的格式示例:
x y Value
1 1 0
1 2 0
1 3 0
1 4 0
1 5 10.159
1 6 5.225
1 7 1.337
1 8 0
1 9 0
1 10 0
我只需要将value字段加载到适当的像素(x, y)。
strtodbl函数只是我写的一个快速的东西,用来替换atof和/或strtod。
EDIT: IMAGE_SIZE_X和IMAGE_SIZE_Y只是图像大小的常量(97x56)。
您已经将data
声明为指向指针的指针,并且您正在使用data
,但您从未分配空间并设置data
指向它。您必须在尝试读取/写入data
应该指向的内容之前这样做。
相关文章:
- OpenSSL 解密功能无法正常工作
- 链表中的显示功能无法正常工作
- 打印功能无法正常工作 - 链表
- 排序功能在C++中未按预期工作
- 如何组织 git 工作流以修复错误并同时引入新功能
- 为什么必须动态分配扩展数组才能使此功能正常工作C++
- Qt C++括号匹配和突出显示当前线路功能无法协同工作
- 下面的代码是如何工作的?它输出分解的数字并且功能齐全,我只是不明白它是如何做到的
- C 功能如何内部工作
- 大写功能无法正常工作
- 为什么这个base64解码/编码功能不能正常工作?
- 如何使功能"run"工作。程序在调用运行时退出
- C 11螺纹 - 非静态成员功能的使用无效 - 工作GCC 5.1.0损坏的GCC 7.3.1
- Lower_bound功能无法正常工作
- 仅一个功能的链接错误.在同一类和CPP文件中具有相似签名的其他函数工作正常
- 功能测试宏在 Visual C++ 中无法正常工作
- 将Linux打开,读,写,关闭功能以在Windows上工作
- 如何使用字符串更改此插入功能以在链接列表中工作
- 澄清功能如何工作并与类相关
- C //尝试重写一个工作代码以包括我的功能