| | |
wrote to binary file, but...
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
BTW, in this case im using just rgbb[0] because im using a PBM file, with is a black and white and just use one bit per pixel, so i dont need rgbb[0] rgbb[1] rgbb[2]..but i keep the array because my program can open all types of pnm files(ppm, pbm, pgm, ascii and binary modes)
With the ascii files im having no problems..
With the ascii files im having no problems..
•
•
•
•
From what you posted earlier it still looks like rgbb is uninitialized. Do you write rgbb in text files too?
I dont get very well what do you mean, I do not initialize rgbb with default values, i just start use it when reading the pixel map from the original file:
C++ Syntax (Toggle Plain Text)
readPNM.read(&img_pix[i].rgbb[0],1);
At this point I think you probably need to use your compiler's debugger, put a break point on that write line and inspect the value of that array. You have only posted one line from your program so its pretty impossible for anyone to tell you the solution to the problem. Possibly its not that line at all but somewhere else in the program, such as memory corruption.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
It would seem impossible for your original code (in post 1) to write more than width * height + 25 bytes (give or take a few bytes for different widths since you are writing these as text), so if you are getting 8 times this many bytes your problem must lie elsewhere. You need to attach your (minimal) program and data file.
•
•
Join Date: Nov 2007
Posts: 980
Reputation:
Solved Threads: 210
•
•
•
•
using this :
the file gets 10,7 MB o__o"C++ Syntax (Toggle Plain Text)
writer.write(reinterpret_cast<char*>(&img_pix[i].rgb) ,sizeof(img_pix[i].rgb));
using this :
the file gets 3,4 MB ..C++ Syntax (Toggle Plain Text)
writer.write(reinterpret_cast<char*>(&img_pix[i].rgb[0]) ,sizeof(img_pix[i].rgb[0]));
using this:
the file gets 914KBC++ Syntax (Toggle Plain Text)
writer.write(&img_pix[i].rgbb[0],sizeof(img_pix[i].rgbb[0]));
using this:
the file gets 2,67 MBC++ Syntax (Toggle Plain Text)
writer.write(reinterpret_cast<char*>(&img_pix[i].rgbb) ,sizeof(img_pix[i].rgbb));
using this:
the file gets 914 KBC++ Syntax (Toggle Plain Text)
writer.write(reinterpret_cast<char*>(&img_pix[i].rgbb[0]) ,sizeof(img_pix[i].rgbb[0]));
Maybe relax and try to master e.g. a binary .pnm file of a very small size, say 2x2 pixels hence being easily viewed in any hexeditor at a glance (notepad and wordpad surely are poor choices for checking the files' content).
Try for example the following struct for reading/writing
C++ Syntax (Toggle Plain Text)
struct Pixel { // 3 bytes represents a single pixel unsigned char rgb[3]; };
Then when you read in the file you might
C++ Syntax (Toggle Plain Text)
// ... code here to read in the file's header ... // allocate enough memory to read in rest of the file const int pixels = width * height; Pixel * p = new Pixel[pixels]; for(int ii = 0; ii < pixels; ++ii) { // read 3 bytes at a time if( ! file.read(reinterpret_cast<char *>(p[ii].rgb), 3)) { // should not happen, handle error ... break; } } // all done
Then to write the file, you can iterate over the array issuing
file.write(reinterpret_cast<const char *>(p[ii].rgb), 3) Remember that the second parameter to both
read() and write() determines how many bytes each I/O operation involves. Im attaching a .zip file with the cpp and the image files im using to test the program..**
mitrmkar, but I think this is exactly what Im doing now, I tried with unsigned char and the method you said, and got the same 914KB result..
"determines how many bytes each I/O operation involves."
In the case of a pbm file, the map of pixels is just one bit per pixel( black or white)..
I still dont get how can the problem come just AFTER all the writing (or
reading)..?
Edit: Ah..I dont know how I can see whats going on by debugging it, since the array is dynamic allocated I cant watch it, and I dont have idea of how can I check the fstreams...
**Damn, Im getting upload error with the attachment of the file, is this temporary or I have problems?
mitrmkar, but I think this is exactly what Im doing now, I tried with unsigned char and the method you said, and got the same 914KB result..
"determines how many bytes each I/O operation involves."
In the case of a pbm file, the map of pixels is just one bit per pixel( black or white)..
I still dont get how can the problem come just AFTER all the writing (or
reading)..?
Edit: Ah..I dont know how I can see whats going on by debugging it, since the array is dynamic allocated I cant watch it, and I dont have idea of how can I check the fstreams...
**Damn, Im getting upload error with the attachment of the file, is this temporary or I have problems?
Last edited by Icebone1000; Mar 18th, 2009 at 9:06 am.
C++ Syntax (Toggle Plain Text)
+ rgbb 0x0044714c "øÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍþÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ" unsigned char [3]
Hey, look this..thats a watching to img_pix[10000] on the reading momment...Im imagining it are getting right the one bit it suppose to, but since i have a byte on rgbb[0] it let the empty spaces after the bit with junk..And when Im writing to a new file, it writes just the bits, and put all this junk just after it??...Am Im imagining too much?
•
•
Join Date: Nov 2007
Posts: 980
Reputation:
Solved Threads: 210
•
•
•
•
C++ Syntax (Toggle Plain Text)
+ rgbb 0x0044714c "øÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÿÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍþÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ" unsigned char [3]
And when Im writing to a new file, it writes just the bits, and put all this junk just after it??...Am Im imagining too much?
write() , that specifies how many bytes are written.PS. Maybe you could try to re-post your code
![]() |
Similar Threads
- Problem with binary data reading (C)
- How to make EXE file from assembly? (Assembly)
- VB 6.0. Creating a file for random access (Visual Basic 4 / 5 / 6)
- Dynamic array (C++)
- Pascal -> C++; Binary, convert? (C++)
- Custom Class - File I/O (C++)
- reading a file into code (Java)
- Array limit (C)
Other Threads in the C++ Forum
- Previous Thread: Pass variables to cmd?
- Next Thread: Code::Blocks: Issue building and running C++ progs between varying versions?
Views: 1058 | Replies: 23
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream input int integer java lazy lib linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






