gdi+图像裁剪

来源:互联网 发布:轰炸商务印书馆知乎 编辑:程序博客网 时间:2024/05/16 14:19

一、实现图像裁剪

CImage image1;//不知道为什么,没有这两句不能正常显示,哪位大神知道告诉我一下image1.Load(L"");//不知道为什么,没有这两句不能正常显示,哪位大神知道告诉我一下CDC* pDC = GetDC();Graphics graph(pDC->GetSafeHdc());Bitmap *image = new Bitmap(_T("d://2.jpg"));graph.DrawImage(image, 0, 0);Image* pScaledImage = FixedSize(image, 200, 200);graph.DrawImage(pScaledImage, 600, 0);

二、FixedSize函数的实现

Image* FixedSize(Image *imgSrc, int Width, int Height){int w, h;w = imgSrc->GetWidth();h = imgSrc->GetHeight();if (w < h) //图片是竖着的 交换Width和Height{Width = Width + Height;Height = Width - Height;Width = Width - Height;}Bitmap *bmPhoto = new Bitmap(Width, Height);bmPhoto->SetResolution(imgSrc->GetHorizontalResolution(), imgSrc->GetVerticalResolution());Graphics grPhoto(bmPhoto);grPhoto.Clear((ARGB)Color::White);grPhoto.SetInterpolationMode(InterpolationModeHighQualityBicubic);grPhoto.DrawImage(imgSrc, 0, 0, 100,0, Width,Height, UnitPixel);//关键代码,实现裁剪return bmPhoto;}

三、运行结果