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. Help!!Get image and save at local computer...

Help!!Get image and save at local computer...

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 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.
  • M Offline
    M Offline
    mimimimilaw
    wrote on last edited by
    #1

    Here is the code the get image and save as the computer!!!However, sometimes the image did not get all bytes. (e.g image size= 85,687 bytes but it only get 75,776 bytes) It is sometimes only.....I don't know what the problem is? Can anyone help? UINT nBytesRead; TCHAR szBuf[CHUNK_SIZE] = {0}; CFile objThumbFile; CHttpFile* pHttpFile = pHttpConnection->OpenRequest (_T("GET"), _T(strPhotoLink), NULL, 1, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD); CString strResponse; if(!objThumbFile.Open(strOutputFileName, CFile::modeCreate | CFile::modeWrite, NULL)) return false; // 7. Read the response text do { nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); strResponse += szBuf; objThumbFile.Write(szBuf, CHUNK_SIZE); //if(nBytesRead < CHUNK_SIZE) //break; i++; //}while(nBytesRead == CHUNK_SIZE); }while(nBytesRead > 0); objThumbFile.Close();

    H D 2 Replies Last reply
    0
    • M mimimimilaw

      Here is the code the get image and save as the computer!!!However, sometimes the image did not get all bytes. (e.g image size= 85,687 bytes but it only get 75,776 bytes) It is sometimes only.....I don't know what the problem is? Can anyone help? UINT nBytesRead; TCHAR szBuf[CHUNK_SIZE] = {0}; CFile objThumbFile; CHttpFile* pHttpFile = pHttpConnection->OpenRequest (_T("GET"), _T(strPhotoLink), NULL, 1, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD); CString strResponse; if(!objThumbFile.Open(strOutputFileName, CFile::modeCreate | CFile::modeWrite, NULL)) return false; // 7. Read the response text do { nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); strResponse += szBuf; objThumbFile.Write(szBuf, CHUNK_SIZE); //if(nBytesRead < CHUNK_SIZE) //break; i++; //}while(nBytesRead == CHUNK_SIZE); }while(nBytesRead > 0); objThumbFile.Close();

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      You can use also from URLDownloadToFile

      _**


      **_

      WhiteSky


      1 Reply Last reply
      0
      • M mimimimilaw

        Here is the code the get image and save as the computer!!!However, sometimes the image did not get all bytes. (e.g image size= 85,687 bytes but it only get 75,776 bytes) It is sometimes only.....I don't know what the problem is? Can anyone help? UINT nBytesRead; TCHAR szBuf[CHUNK_SIZE] = {0}; CFile objThumbFile; CHttpFile* pHttpFile = pHttpConnection->OpenRequest (_T("GET"), _T(strPhotoLink), NULL, 1, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD); CString strResponse; if(!objThumbFile.Open(strOutputFileName, CFile::modeCreate | CFile::modeWrite, NULL)) return false; // 7. Read the response text do { nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); strResponse += szBuf; objThumbFile.Write(szBuf, CHUNK_SIZE); //if(nBytesRead < CHUNK_SIZE) //break; i++; //}while(nBytesRead == CHUNK_SIZE); }while(nBytesRead > 0); objThumbFile.Close();

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        mimimimilaw wrote:

        strResponse += szBuf;

        If szBuf contains more than one \0 character, this obviously will not work.


        "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

        "Judge not by the eye but by the heart." - Native American Proverb

        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