| | |
C++ raster files (writing structs to a binary file)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Solved Threads: 0
Im trying to write a struct for a binary header of a sun raster file to a file on disk.
i have a struct for the header data:
But when i open this in a graphics veiwer I get told that the header is invalid.
Any ideas on a better way to output a struct to a binary file???? Anyone done any raster stuff before??
Thanks!
Josh
i have a struct for the header data:
C++ Syntax (Toggle Plain Text)
struct rasterfile { int ras_magic; int ras_width; int ras_height; int ras_depth; int ras_length; int ras_type; int ras_maptype; int ras_maplength; }; which i then fill with the data for my raster file: rasterfile fileheader; void setHeader() { // Fills the raster header with default values... fileheader.ras_magic = 0x59a66a95; fileheader.ras_width = 768; fileheader.ras_height = 576; fileheader.ras_depth = 24; fileheader.ras_length = 0;//1327104; fileheader.ras_type = 0; // RGB instead of BGR??? fileheader.ras_maptype = 0; fileheader.ras_maplength = 0; } I then write to the file using this: void writetofile() { //ouputs the header and the bitmap array to file ofstream myFile ("purple.ras", ios::out | ios::binary); myFile.write ((char*)&fileheader.ras_magic, 32); myFile.write ((char*)&fileheader.ras_width, 32); myFile.write ((char*)&fileheader.ras_height, 32); myFile.write ((char*)&fileheader.ras_length, 32); myFile.write ((char*)&fileheader.ras_type, 32); myFile.write ((char*)&fileheader.ras_maptype, 32); myFile.write ((char*)&fileheader.ras_maplength, 32); myFile.write ((char*)&bitmap, sizeof (bitmap)); myFile.close(); }
But when i open this in a graphics veiwer I get told that the header is invalid.
Any ideas on a better way to output a struct to a binary file???? Anyone done any raster stuff before??
Thanks!
Josh
Last edited by WolfPack; Jul 27th, 2006 at 8:33 am.
![]() |
Similar Threads
- How to parse binary file (C++)
- Binary File Parser (C++)
- C++ How to write strings to a Binary file? (C++)
- reading ints from a binary file (C)
- Reading or writing a double into a bin file (C++)
Other Threads in the C++ Forum
- Previous Thread: Help C++ Assignment - NO CLUE
- Next Thread: problem creating a for loop for an array
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets




