GDI+图像的显示、裁剪、缩放、转置、镜像、旋转、变形

 

 

GDI+的配置:

http://blog.csdn.net/lys07962000/article/details/8948996 

 

void CXXDlg::OnPaint()

{

.......

// 图像的显示
 /*CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Image image(L"pic.jpg");

 graph.DrawImage(&image, 70, 50);
 ReleaseDC(pDC);

 // 使用负坐标显示图像
 
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Image image(L"pic.jpg");

 graph.DrawImage(&image, -70, -50);
 ReleaseDC(pDC);*/

 // 不同分辨率图片的显示情况
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Image image(L"pic.jpg");

 graph.DrawImage(&image, 0, 0); // 绘制图像

 CString strPrint;    // 输出的字符串
 double f = graph.GetDpiX() / image.GetHorizontalResolution(); // 缩放比例

 strPrint.Format(L"屏幕分辨率是%.0f, 图像分辨率是%.0f, 缩放比例是%.1f",
  graph.GetDpiX(), image.GetHorizontalResolution(), f);
 graph.DrawString(strPrint, -1, &Font(L"黑体", 17, FontStyleBold),
  PointF(0, 280), &SolidBrush(Color::Red));

 ReleaseDC(pDC);*/

 // 图像的缩放方法1
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());

 CRect winRect;
 GetClientRect(winRect);  // 获得窗口绘制区的大小

 Image image(L"pic.jpg");
 graph.DrawImage(&image, 0, 0,  winRect.Width(), winRect.Height()); // 绘制图像

 ReleaseDC(pDC);*/
 
 // 图像的缩放方法2
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());

 CRect winRect;
 GetClientRect(winRect);  // 获得窗口绘制区的大小

 Rect rect(0, 0, winRect.Width(), winRect.Height()); // 创建绘制区域的矩形对象

 Image image(L"pic.jpg");
 graph.DrawImage(&image, rect); // 绘制图像

 ReleaseDC(pDC);*/

 /*****************************************************************************
          6.4.4节代码
 *****************************************************************************/

 // 图像的剪裁显示
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Image image(L"pic.jpg");

 // 从原图片的(12, 80)开始,剪裁长为430,宽为180的矩形区域
 // 然后将其显示在(80, 90)处
 graph.DrawImage(&image, 80, 90, 12, 80, 430, 180, UnitPixel);

 ReleaseDC(pDC);*/

 // 剪裁并缩放图像
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Image image(L"pic.jpg");
 int nSrcWidth = 430; // 剪裁区域的宽度
 int nSrcHeight = 180; // 剪裁区域的高度
 // 构造显示的矩形区域
 Rect destRect(15, 40, (int)(nSrcWidth*1.2), (int)(nSrcHeight*1.2));

 graph.DrawImage(&image, destRect, 12, 80, nSrcWidth, nSrcHeight, UnitPixel);

 ReleaseDC(pDC);*/

 // 图像的转置
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Bitmap image(L"pic.jpg");

 
 // 输出原始图像
 graph.DrawImage(&image, 0, 0);

 // 输出转置图像的坐标
 int nX = 500;
 int nY = 0;

 // 图像长宽
 int nWidth = image.GetWidth();
 int nHeight = image.GetHeight();

 Point points[] = {     // 输出位置需要加上转置图像的坐标
  Point(nX, nY),      // 原图像左上角的输出位置
  Point(nX, nY + nWidth),    // 原图像右上角的输出位置
  Point(nX + nHeight, nY) };   // 原图像左下角的输出位置

 graph.DrawImage(&image, points, 3);

 ReleaseDC(pDC);*/

 // 图像的镜像
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Bitmap image(L"pic.jpg");
 
 // 图像长宽
 int nWidth = image.GetWidth();
 int nHeight = image.GetHeight();

 // 水平镜像的输出位置
 int nX = 0;
 int nY = 0;

 Point HoPoints[] = {
   Point(nX + nWidth, nY),    
   Point(nX, nY),      
   Point(nX + nWidth, nY + nHeight) };

 graph.DrawImage(&image, HoPoints, 3);   // 输出水平镜像

 // 垂直镜像的输出位置
 nX = nWidth + 5;
 nY = 0;

 Point VePoints[] = {
  Point(nX, nY + nHeight),    
  Point(nX + nWidth, nY + nHeight),      
  Point(nX, nY) };

 graph.DrawImage(&image, VePoints, 3);   // 输出垂直镜像

 ReleaseDC(pDC);*/
 
 // 图像的简单旋转
 /*
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Bitmap image(L"pic.jpg");
 
 // 图像长宽
 int nWidth = image.GetWidth();
 int nHeight = image.GetHeight();

 // 旋转90度图像的输出位置
 int nX = 0;
 int nY = 0;

 Point points90[] = {
   Point(nX + nHeight, nY),
   Point(nX + nHeight, nY + nWidth),
   Point(nX, nY) };

 graph.DrawImage(&image, points90, 3); // 输出旋转了90度的图像

 // 旋转180度图像的输出位置
 nX = nHeight + 5;
 nY = 0;

 Point points180[] = {
  Point(nX + nWidth, nY + nHeight),
  Point(nX, nY + nHeight),
  Point(nX + nWidth, nY) };

 graph.DrawImage(&image, points180, 3); // 输出旋转了180度的图像

 ReleaseDC(pDC);*/

 // 图像的变形
 
 CDC* pDC = GetDC();
 Graphics graph(pDC->GetSafeHdc());
 Bitmap image(L"pic.jpg");
 
 // 图像长宽
 int nWidth = image.GetWidth();
 int nHeight = image.GetHeight();

 // 变形图像1的输出位置
 int nX = 0;
 int nY = 0;

 Point points1[] = {
   Point(nX, nY),
   Point(nX + nWidth, nY + 0),
   Point(nX + 60, nY + nHeight) };

 graph.DrawImage(&image, points1, 3); // 输出变形图形1

 // 变形图像2的输出位置
 nX = 520;
 nY = 0;

 Point points2[] = {
  Point(nX + 52, nY),
  Point(nX + 374, nY + 200),
  Point(nX, nY + 117) };

 graph.DrawImage(&image, points2, 3); // 输出变形图形2

 

......

}

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值