samedi 5 juillet 2014

Creating and Saving New Photos Win32 Webcam Application


Vote count:

0




I am trying to make my webcam Win32 application save more than one photo at a time i.e. save one photo then another then another etc.


To do this, I am appending a string to an integer variable so that each new photo name can be unique and conform to the format of the second argument of CreateBMPFile. This would usually be a case of writing TEXT("string literal"), but I need to keep modifying the filename as each new photo is created.



PBITMAPINFO pbi = CreateBitmapInfoStruct(hwnd, hbm);
int i = 1;
std::string image = "..\\..\\..\\..\\WebCam\\frame" + std::to_string(i) + ".bmp";
while (!exists(image)) {
LPTSTR filename = (LPTSTR)image.c_str();
CreateBMPFile(hwnd, filename, pbi, hbm, hdcMem);
i++;
}


This compiles and executes, however, it crashes the program upon taking a photo.


I am using an exists() function to see whether the file exists in the system:



inline bool exists(const std::string& name) {
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}


I've also tried using sprintf_s() with the same result of crashing the application.



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire