簡體   English   中英

如何在C ++中監視目錄並讀取此目錄中的圖像

[英]How to monitor a directory and read image in this directory in C++

首先,我是C ++的新手。 我正在使用Visual Studio2010。我從事的項目包括相機。 相機將圖像(位圖)發送到計算機中的特定文件夾位置。 我要一直監視目錄。 在目錄中獲得新的位圖圖像時,我要處理該圖像。 我要使用的代碼始終監視目錄並讀取該目錄中的最后一個位圖圖像。 我可以用什么來實現它? 您有什么建議? 你能寫源代碼嗎? 謝謝你的關注。

Windows ReadDirectoryChangesW API可用於監視目錄中是否有添加的文件。 但是,它非常高級,如果您是C ++和Windows編程的新手,那么它可能超出了您的實現范圍。 您將需要一些經驗豐富的幫助。

我不同意回答該問題的其他人,可以通過下面使用的一些共存庫輕松完成此代碼,此代碼可以滿足您的需求,

string processName()
{

   FILETIME bestDate = { 0, 0 };
   FILETIME curDate;
   string name;
   CFileFind finder;


   BOOL bWorking = finder.FindFile("*.png");

   while (bWorking)
   {

      bWorking = finder.FindNextFile();

     // date = (((ULONGLONG) finder.GetCreationTime(ft).dwHighDateTime) << 32) + finder.GetCreationTime(ft).dwLowDateTime;

      finder.GetCreationTime(&curDate);

      if (CompareFileTime(&curDate, &bestDate) > 0 )
      {
          bestDate = curDate;
          name = finder.GetFileName().GetString();
          // name = (LPCTSTR) finder.GetFileName();
      }



   }
   return name;
}

在這里,我為您編寫了代碼,它采用了最后輸入的/.png擴展名,您可以檢查libray。

請告訴我進一步的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM