recently i have noticed that we can save images from highgui window by pressing CTRL+S ( Afaik it is only for windows platform ).
when CTRL+S pressed a save dialog appears and you can choose the format of image to save. but all the formats listed in the save dialog.
as shown below i tried to modify source code to check if image formats supported by compiled library ( for example my library compiled only WITH_JPEG option)
i could not do #ifdef HAVE_PNG, need help at this point. thanks in advance.
static void showSaveDialog(CvWindow* window)
{
if (!window || !window->image)
return;
SIZE sz;
int channels;
void* data;
if (icvGetBitmapData(window, &sz, &channels, &data))
return; // nothing to save
char szFileName[MAX_PATH] = "";
// try to use window title as file name
GetWindowText(window->frame, szFileName, MAX_PATH);
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
#ifdef OPENFILENAME_SIZE_VERSION_400
// we are not going to use new fields any way
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
#else
ofn.lStructSize = sizeof(ofn);
#endif
ofn.hwndOwner = window->hwnd;
// *** need help here,how to check HAVE_PNG ?? #ifdef HAVE_PNG ***
ofn.lpstrFilter = "Portable Network Graphics files (*.png)\0*.png\0"
#ifdef HAVE_JPEG
"JPEG files (*.jpeg;*.jpg;*.jpe)\0*.jpeg;*.jpg;*.jpe\0"
#endif
"Windows bitmap (*.bmp;*.dib)\0*.bmp;*.dib\0"
#ifdef HAVE_TIFF
"TIFF Files (*.tiff;*.tif)\0*.tiff;*.tif\0"
#endif
#ifdef HAVE_JASPER
"JPEG-2000 files (*.jp2)\0*.jp2\0"
#endif
#ifdef HAVE_WEBP
"WebP files (*.webp)\0*.webp\0"
#endif
"Portable image format (*.pbm;*.pgm;*.ppm;*.pxm;*.pnm)\0*.pbm;*.pgm;*.ppm;*.pxm;*.pnm\0"
#ifdef HAVE_OPENEXR
"OpenEXR Image files (*.exr)\0*.exr\0"
#endif
"Radiance HDR (*.hdr;*.pic)\0*.hdr;*.pic\0"
"Sun raster files (*.sr;*.ras)\0*.sr;*.ras\0"
"All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN | OFN_NOCHANGEDIR;
ofn.lpstrDefExt = "png";
if (GetSaveFileName(&ofn))
{
cv::Mat tmp; cv::flip(cv::Mat(sz.cy, sz.cx, CV_8UC(channels), data), tmp, 0);
cv::imwrite(szFileName, tmp);
}
}