为 ppm/pgm 图像数据创建存储
Creating storage for ppm/pgm image data
所以我正在研究一个应该在pgm/ppm文件中读取并最终修改它的类。但是,我仍在努力读取数据。我目前的目标是为二进制数据创建存储空间。下面是我应该这样做的函数的代码:
uchar* pxm::newimg(int nrows, int ncols, int bpp)
{
uchar *newimage = new uchar[nrows * ncols * bpp];
//uchar defined as binary data previously
return newimage;
}
然后,我在"读取"函数中使用它作为:
img = newimg(nrows, ncols, bpp); //img declared in private section of class
ws(myfile); //reads the newline
myfile.read((char *) img[0], nrows * ncols * bpp);
//nrows, ncols, and bpp private member variables in class
myfile.close();
遗憾的是,当此代码编译时,它会在运行时产生分段错误。我相当确定我的问题出在 newimg 函数中,因为我已经进行了检查以确保我正确读取文件并正确设置 nrows、ncols 和 bpp,以及 magicid。因此,我认为我没有正确初始化数组数据结构。如果有人有任何建议,将不胜感激。谢谢截塔附言如果您需要有关我的代码的更多详细信息,请请求它,我将在帖子中添加更多内容。
(char *) img[0]
应该是img
,或者(char *) img
。
相关文章:
- 从 bmp 文件数据创建 MFC CBitmap
- 如何在 QML 中使用从 c++ 公开的序列数据创建图表
- c++用输入数据创建数组
- 使用 2D 数据创建 3D 直方图(OpenCV?
- 如何使C++代码更快:使用 CFile 从相机数据创建.csv文件
- 使用 C++ 从 16 位数据创建灰度图像
- 如何根据过滤的数据创建笛卡尔产品范围
- C 双重调度,出厂模式或一种从接收到的序列数据创建派生对象的方法
- 为 ppm/pgm 图像数据创建存储
- 如何从二进制数据创建 QIcon
- 基于输入数据创建 STL 向量 - 标量或复杂类型
- DirectX11如何从未签名的char*数据创建Texture2D
- 使用相机的初始数据创建d3d11Texture2D
- OpenCV C++:从存储在 int 向量的索引中为垫子类型数据创建列范围
- 如何使用矢量中的数据创建矢量
- 从单独文件(C++)中的用户输入数据创建矢量
- 为二进制数据创建字符串缓冲区的最佳方法
- 使用Media Foundation从原始数据创建AAC文件
- 在Visual Studio 2013中使用c++中的对象字段数据创建图表
- 如何从变量数据创建std::initializer_list