zoukankan      html  css  js  c++  java
  • 图像旋转的C#示例

    private void RotateTransform_Click(object sender, System.EventArgs e)
            {
                Graphics graphics
    =this.CreateGraphics();
                graphics.Clear(Color.White);

                
    //装入图片
                Bitmap image=new Bitmap("nemo.bmp");

                
    //获取当前窗口的中心点
                Rectangle rect=new Rectangle(0,0,this.ClientSize.Width,this.ClientSize.Height);
                PointF center
    =new PointF(rect.Width/2,rect.Height/2);

                
    float offsetX=0;
                
    float offsetY=0;
                offsetX
    =center.X-image.Width/2;
                offsetY
    =center.Y-image.Height/2;
                
    //构造图片显示区域:让图片的中心点与窗口的中心点一致
                RectangleF picRect=new RectangleF(offsetX,offsetY,image.Width,image.Height);
                PointF Pcenter
    =new PointF(picRect.X+picRect.Width/2,
                    picRect.Y
    +picRect.Height/2);
        
                
    //让图片绕中心旋转一周
                for(int i=0;i<361;i+=10)
                {
                    
    // 绘图平面以图片的中心点旋转
                    graphics.TranslateTransform(Pcenter.X, Pcenter.Y);
                    graphics.RotateTransform(i);
                    
    //恢复绘图平面在水平和垂直方向的平移
                    graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y);
                    
    //绘制图片并延时
                    graphics.DrawImage(image,picRect);    
                    Thread.Sleep(
    100);
                    
    //重置绘图平面的所有变换
                    graphics.ResetTransform();
                }
            } 
  • 相关阅读:
    python的正负无穷float("inf")的用法
    python中几个常见的黑盒子之“字典dict” 与 “集合set”
    python中几个常见的“黑盒子”之 列表list
    Python 排序---sort与sorted学习
    django中使用Profile扩展User模块(基于django 1.10版本下)
    获取Linux进程运行在哪个CPU内核上面的方法
    【转】Crontab定时任务配置
    【转】sudo命令情景分析
    【转】详解Python的装饰器
    一步步来配置安卓开发环境ADTBundle
  • 原文地址:https://www.cnblogs.com/kenter/p/2122973.html
Copyright © 2011-2022 走看看