开发者

Question about CImage save function

开发者 https://www.devze.com 2023-01-28 04:20 出处:网络
I have encountered a problem while saving the CImage class data. The following are my brief set up: #include \"stdafx.h\"

I have encountered a problem while saving the CImage class data. The following are my brief set up:

#include "stdafx.h"
#include <cstring>
#include <atlimage.h>
#include <vector>
#include <stdlib.h>
#include <cmath>
#include <algorithm>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
   CImage myimage;
   myimage.Create(100,100,24);
   // save an image in BMP format
   string impath = "image1.bmp"开发者_Go百科;
   myimage.Save((LPCTSTR)impath.c_str());
   return 0;
}

I have run it as a WIN32 console application under VC++ 2008. There is no error. However, after the program done, there is NO file created under my directory. I have run this code on two machines, and the results are the same.

Thank you very much for your time and effort.


Maybe you are just looking in the wrong place for the file. Give an absolute path. The relative path is to the current working directory of the process. If you run from the debugger, it could be the output directory of the executable, the project directory or somewhere else.

Also, instead of the cast use the _T macro on c_str() -- in case it needs a conversion.

If you still can't figure it out, get PROCMON (free utility from Microsoft). Run it and filter the output so it's just looking for file with path contains "image1.bmp" -- it will tell you all file operations that were tried with that path and what happened.


myimage.Save((LPCTSTR)impath.c_str());

1) check result
2) why did you use type casting? this can mask the bug, e.g. if you use UNICODE build (default one in VS2008), filename will be invalid

0

精彩评论

暂无评论...
验证码 换一张
取 消