简体   繁体   English

.raw文件格式C ++

[英].raw file format C++

I want to know is it possible to generate .raw file format using C++. 我想知道是否可以使用C ++生成.raw文件格式。 If yes then which class deals with it? 如果是,那么哪个班级处理它? If possible kindly put down a sample code. 如果可能,请放下示例代码。

I have data of the format (XYZ) <Number> which represents the number of particles between (XYZ) and (X+1 Y+1 Z+1) . 我有格式(XYZ) <Number>数据,它表示(XYZ)(X+1 Y+1 Z+1)之间的粒子数。 I need to represent this data graphically using ParaView and hence need my data in binary format. 我需要使用ParaView以图形方式表示这些数据,因此需要二进制格式的数据。 So would like to know is it possible to directly generate .raw file format? 那么想知道是否有可能直接生成.raw文件格式?

Generally, to write binary data to a file in C++, you will want to use an ofstream : 通常,要将二进制数据写入C ++文件,您需要使用ofstream

#include <fstream.h>
...

{
   MyData myData = GetData();
   ofstream binaryFile ("file.raw", ios::out | ios::binary);
   binaryFile.write ((char*)&myData, sizeof (MyData));
   binaryFile.close();
}

It is up to you to determine the actual format (like the Data structure in the example above) that this application uses, and then write it to a file. 由您决定此应用程序使用的实际格式(如上例中的Data结构),然后将其写入文件。

There are many definitions of raw image files, it very much depends on the context. 原始图像文件有很多定义,它在很大程度上取决于上下文。 The oldest and simplest definition is a file with no header and with pixel values packed in binary without any compression. 最旧和最简单的定义是没有标题的文件,并且像素值以二进制形式打包而没有任何压缩。 This is trivial to implement, just write each pixel as 3 unsigned char values for red, green, and blue, from left to right and top to bottom. 实现起来很简单,只需将每个像素写成红色,绿色和蓝色的3个unsigned char值,从左到右,从上到下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM