我想写一个裁剪指定目录下图片的程序,现在在裁剪方面出了点问题。关键代码如下。现在执行的效果是通过CImage对象能实现图片的保存。但没有裁剪的效果。我是通过CIMAGE获得图片的DC,通过DC设定裁剪区域,再通过相同的内存DC复制到指定区域,不知道为什么不行。大家不吝赐教
         while(nSize)
{

path = filePath.GetAt(nSize); //filename为要加载的文件地址 
image.Load(path);

//待裁剪后的图像矩形
int width = image.GetWidth();
int height = image.GetHeight(); rect.left = (width - m_width) / 2;
rect.top = (height - m_height) / 2; rect.right = (width + m_width) / 2;
rect.bottom = (height + m_height) / 2;; rgn.CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);

//得到一个内存DC
cdc = CDC::FromHandle(image.GetDC());
hmdc.CreateCompatibleDC(cdc);
image.ReleaseDC();

//载入位图到内存dc
hBitmap = image.Detach();
image.Attach(hBitmap);

bmp.Attach(hBitmap);
hmdc.SelectObject(bmp); //得到剪贴区
cdc->SelectClipRgn(&rgn, RGN_COPY);
cdc->BitBlt(0, 0, m_width, m_height, &hmdc, 0, 0, SRCOPY); 
//保存文件
savePath = m_outputDir + "\\" + fileName.GetAt(nSize);
image.Save(savePath);
nSize --;
image.Detach();
hmdc.DeleteDC();
rgn.Detach();
bmp.Detach();

}