封装DLL 截取图片中一部分,另存为另外一张图片,图片没显示
请教下各位大侠:
我用VS2005 MFC封装DLL中,实现截取bmp图片的一部分,然后把截取的内容,另存为一张新的bmp图片。但是,图片没有显示出来,不知道哪里出问题了。
代码如下:
[code=C/C++][/code]//取出指定范围内的矩形区域
LPCTSTR sType;
sType = (LPCTSTR)"image/bmp";
int i;
CLSID clsid;
//GetEncoderClsid((wchar_t*)sType,&clsid);
::CoCreateGuid(&clsid);
CString ss,sFile,img_path;
img_path = (CString)path_img;
Bitmap bt((wchar_t*)strFileName);
Bitmap *bts = bt.Clone(min_x,min_y,max_x-min_x,max_y-min_y,0);
//新建指定大小的图片
Bitmap bmp( max_x-min_x,max_y-min_y );
//从它得到绘制设备
Graphics *gc = Graphics::FromImage( &bmp );
gc->DrawImage( bts,0,0 );
sFile.Format(_T("%s2.%s"),(LPCTSTR)img_path,"bmp"); //保存的图片格式及路径
bmp.Save( (wchar_t*)(LPCTSTR)sFile,&clsid,NULL );
//AfxMessageBox((LPCTSTR)sFile);
[解决办法]
bt.Clone(min_x,min_y,max_x-min_x,max_y-min_y,0); 最后面这个参数不能为零吧。
[解决办法]
你没有把图片显示在屏幕的代码
Graphics *gc = Graphics::FromImage( &bmp );
gc->DrawImage( bts,0,0 );
这两句只是把图片会在在一个Bitmap画布上