当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Creating and Saving New Photos Win32 Webcam Application

问题描述:

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, when I click the "Grab Frame" button and it attempts to save it, the application crashes i.e. I cannot see the GUI anymore and it becomes a stagnant process.

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: