简体   繁体   中英

.raw file format C++

I want to know is it possible to generate .raw file format using C++. 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) . I need to represent this data graphically using ParaView and hence need my data in binary format. So would like to know is it possible to directly generate .raw file format?

Generally, to write binary data to a file in C++, you will want to use an 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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