C++ raster files (writing structs to a binary file)

Please support our C++ advertiser: Intel Parallel Studio Home
Closed Thread

Join Date: Oct 2004
Posts: 11
Reputation: mr_mooz is an unknown quantity at this point 
Solved Threads: 0
mr_mooz mr_mooz is offline Offline
Newbie Poster

C++ raster files (writing structs to a binary file)

 
0
  #1
Oct 27th, 2004
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:

  1. struct rasterfile {
  2. int ras_magic;
  3. int ras_width;
  4. int ras_height;
  5. int ras_depth;
  6. int ras_length;
  7. int ras_type;
  8. int ras_maptype;
  9. int ras_maplength;
  10. };
  11.  
  12.  
  13.  
  14. which i then fill with the data for my raster file:
  15.  
  16. rasterfile fileheader;
  17.  
  18.  
  19. void setHeader()
  20. { // Fills the raster header with default values...
  21.  
  22. fileheader.ras_magic = 0x59a66a95;
  23. fileheader.ras_width = 768;
  24. fileheader.ras_height = 576;
  25. fileheader.ras_depth = 24;
  26. fileheader.ras_length = 0;//1327104;
  27. fileheader.ras_type = 0; // RGB instead of BGR???
  28. fileheader.ras_maptype = 0;
  29. fileheader.ras_maplength = 0;
  30.  
  31. }
  32.  
  33. I then write to the file using this:
  34.  
  35. void writetofile()
  36. { //ouputs the header and the bitmap array to file
  37.  
  38. ofstream myFile ("purple.ras", ios::out | ios::binary);
  39. myFile.write ((char*)&fileheader.ras_magic, 32);
  40. myFile.write ((char*)&fileheader.ras_width, 32);
  41. myFile.write ((char*)&fileheader.ras_height, 32);
  42. myFile.write ((char*)&fileheader.ras_length, 32);
  43. myFile.write ((char*)&fileheader.ras_type, 32);
  44. myFile.write ((char*)&fileheader.ras_maptype, 32);
  45. myFile.write ((char*)&fileheader.ras_maplength, 32);
  46. myFile.write ((char*)&bitmap, sizeof (bitmap));
  47. myFile.close();
  48. }


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.
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC