How to save a cam snapshot?

I have an unsigned char array, where the cam driver gives me the image data:
unsigned char* imgBuf = new unsigned char[imgSize];
ASIGetDataAfterExp(CamNum, imgBuf, imgSize);

ho to save this with opencv ?
I tried
Mat save_img;
imgBuf >> save_img;
std::cerr << “Something is wrong with the webcam, could not get frame.” << std::endl;
}bei m
// Save the frame into a file
imwrite(“test.jpg”, save_img); // A JPG FILE IS BEING SAVED

but it gives me:
main_SDK2_snap.cpp:255:11: error: no match for \u2018operator>>\u2019 (operand types are \u2018unsigned char*\u2019 and \u2018cv::Mat\u2019)
imgBuf >> save_img;

please help !!!

there is no >> operator for raw pointers here,
but, if you know width, height and type, you can setup a cv::Mat like:

Mat img(h, w, CV_8U); // preallocated 8bit grayscale

// and read your data directly into that
ASIGetDataAfterExp(CamNum,, imgSize);

// Now save the frame into a file
imwrite(“test.jpg”, img);