Reading a jpeg file
-
Hello, I'm trying to read a jpeg file using this code: imageFile.Open(fileTitle,CFile::modeRead,&e); imageFile.ReadHuge(buffer,1000000); imageFile.Close(); ReadHuge reports reading the whole jpeg file; the problem is that all I've got in the buffer is 4 bytes. I guess it's something with the character set; I don't know ... Can someone help me with an example ? How should I be reading the file ?
-
Hello, I'm trying to read a jpeg file using this code: imageFile.Open(fileTitle,CFile::modeRead,&e); imageFile.ReadHuge(buffer,1000000); imageFile.Close(); ReadHuge reports reading the whole jpeg file; the problem is that all I've got in the buffer is 4 bytes. I guess it's something with the character set; I don't know ... Can someone help me with an example ? How should I be reading the file ?
Hi, If I remember correctly, you have posted this question not so long ago... So I am going to reply assuming you did the same thing! You were storing your buffer in a CString. If you do this, the copy will stop when you hit the first byte with a value of 0. I guess the fourth character in your file is 0. If you want to know how many characters you have read do this: DWORD dwNumberOfBytesRead = imageFile.ReadHuge(buffer,1000000); By the way, ReadHuge and Read do the same thing! Good luck!
-
Hi, If I remember correctly, you have posted this question not so long ago... So I am going to reply assuming you did the same thing! You were storing your buffer in a CString. If you do this, the copy will stop when you hit the first byte with a value of 0. I guess the fourth character in your file is 0. If you want to know how many characters you have read do this: DWORD dwNumberOfBytesRead = imageFile.ReadHuge(buffer,1000000); By the way, ReadHuge and Read do the same thing! Good luck!
The problem is not the copying to the CString. The problem is that the buffer is already at 4 bytes before I copy it to the CString. That's the problem and thats what I don't understand ... when I do the DWORD dwNumberOfBytesRead = imageFile.ReadHuge(buffer,1000000); dwNumberOfBytesRead reports 127235 and thats exactly the number of bytes it's supposed to read; but the contents of buffer is only 4 bytes. So , I guess it's because of the character set I use. What can I do ? You try reading a jpeg and you'll see
-
The problem is not the copying to the CString. The problem is that the buffer is already at 4 bytes before I copy it to the CString. That's the problem and thats what I don't understand ... when I do the DWORD dwNumberOfBytesRead = imageFile.ReadHuge(buffer,1000000); dwNumberOfBytesRead reports 127235 and thats exactly the number of bytes it's supposed to read; but the contents of buffer is only 4 bytes. So , I guess it's because of the character set I use. What can I do ? You try reading a jpeg and you'll see
-
OK I am not sure if we are on the same wave length here but try this:
char buffer[1000000]; // This initialises your whole buffer to 0 memset(buffer,0,100000);
then call your read and you will see that the content of your buffer will change.It still doesn't work. You know whats funny ... when I do a copy paste of the contents of the jpeg it pastes nothing. So I guess it doesn't recognize the characters ... Someone ?