Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Reading a jpeg file

Reading a jpeg file

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BlackRider
    wrote on last edited by
    #1

    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 ?

    B 1 Reply Last reply
    0
    • B BlackRider

      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 ?

      B Offline
      B Offline
      BadJerry
      wrote on last edited by
      #2

      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!

      B 1 Reply Last reply
      0
      • B BadJerry

        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!

        B Offline
        B Offline
        BlackRider
        wrote on last edited by
        #3

        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

        B 1 Reply Last reply
        0
        • B BlackRider

          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

          B Offline
          B Offline
          BadJerry
          wrote on last edited by
          #4

          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.

          B 1 Reply Last reply
          0
          • B BadJerry

            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.

            B Offline
            B Offline
            BlackRider
            wrote on last edited by
            #5

            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 ?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups