GDI+ 旋转图片(jpg,bmg,GDI+支持的图像格式)

为了做旋转图片,用了我太多的精力,位图旋转的实现实在是太麻烦了,直到前几天我看到了GDI+,才想出来了这个简单的旋转图像的方法,今天太累了,改天补充出来动画的旋转,希望各位同学一起分享!

在对话框做中的OnPaint()方法中直接写入复制代码就可以了,其他的旋转角度可以自己补充

void CgdiTestDlg::OnPaint()
{
 CPaintDC dc(this); // 用于绘制的设备上下文
 if (IsIconic())
 {

  SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

  // 使图标在工作矩形中居中
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
 // MessageBox(rect.Width());
  
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;

  // 绘制图标
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CDialog::OnPaint();
 }
 Graphics graphics(dc.m_hDC);
 CBrush cbrush(RGB(0,0,255));
 
 Image image(_T("E:\\dyr\\dyr\\DSCF2741.JPG"));
 
 //正常的显示
     Point destPoints1[3] ={Point(10,10),Point(10,410),Point(310,10)};
 //旋转90度显示
 // Point destPoints1[3] ={Point(10,410),Point(10,10),Point(310,410)};


 
 graphics.DrawImage(&image,destPoints1,3);

 

//graph.DrawImage(&image,100,100);

//graph.RotateTransform(30.0f);

//graph.DrawImage(&image,200,200);

}

转载于:https://www.cnblogs.com/zhixing/archive/2011/03/21/1990666.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以前一直不知道在GUI里面画出的图片可以旋转,所以遇到想要旋转图片时,都是把图片贴到一个面片上,旋转面片,很是不方便,最近发现在GUI里是可以旋转图片的,所以写到这里分享给大家。下面贴一个例子,利用图片旋转写的一个钟表的代码,不废话,直接上代码。   var Tu1 : Texture2D;   var Time1 : float = 0;   function FixedUpdate () {    Time1 += Time.deltaTime;   }   function OnGUI () {    GUI.Label(Rect(250,170,161,62),getTime(Time1));       GUIUtility.RotateAroundPivot (6*Time1, Vector2(103, 200));    GUI.DrawTexture(Rect(100,100,6,100),Tu1);//秒针    GUIUtility.RotateAroundPivot (-6*Time1, Vector2(103, 200));       GUIUtility.RotateAroundPivot (0.1*Time1, Vector2(103, 200));    GUI.DrawTexture(Rect(100,120,6,80),Tu1);//分针    GUIUtility.RotateAroundPivot (-0.1*Time1, Vector2(103, 200));       GUIUtility.RotateAroundPivot (0.1/60*Time1, Vector2(103, 200));    GUI.DrawTexture(Rect(100,140,6,60),Tu1);//时针    GUIUtility.RotateAroundPivot (-0.1/60*Time1, Vector2(103, 200));   }    function getTime(time : float) : String{    if(time<0){    return "00:00:00";    }    var lastTime : String = "";    var hour = Mathf.FloorToInt(time/3600$);    if(hour/10 >=1){    lastTime+="" + hour;    }else{    lastTime +="0" + hour;    }    var minute = Mathf.FloorToInt(time/60`);    if(minute/10 >=1){    lastTime+=":" + minute;    }else{    lastTime +=":0" + minute;    }    var second = Mathf.FloorToInt(time`);    if(second/10 >=1){    lastTime+=":" + second;    }else{    lastTime +=":0" + second;    }    return lastTime;   }   简单介绍一下代码   GUIUtility.RotateAroundPivot (6*Time1, Vector2(103, 200))为旋转GUI的代码,第一个参数为旋转的角度,第二个参数为旋转的中心点,在它之下的GUI元素都会执行该旋转,例如图片、文字等。当你只想旋转某一GUI元素而其他元素不旋转事就得给它一个停止旋转的代码,很简单,停止旋转时给它一个反向的角度,ok。   为了便于测试,在钟表左边给出一个数字时间经行对比。getTime(time : float)可用于实现场景中时间的显示,或者倒计时的显示等,需要的直接拿走,哈哈哈~

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值