• 大小: 303KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: C#
  • 标签: c#  课程设计  

资源简介

C#实现将某张照片进行旋转,目前我添加了可以浏览图片,旋转18度和26度,若想旋转其他度数,直接复制button中函数体,修改度数即可。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private const string IMAGEFILE = “G:\\RFID\\1.JPG“;

        private static int MyAngle = 0; //旋转角度[-360360]  



        private void Page_Load(object sender EventArgs e)

        {

            Image img;

            FileStream fs;


            fs = new FileStream(IMAGEFILE FileMode.Open FileAccess.Read);

            img = Bitmap.FromStream(fs);

            fs.Close();

            pictureBox1.Image = img;

        }

        private void button1_Click(object sender EventArgs e)
        {
              
            
            MyAngle = 0;

            //MyAngle += 90;  

            //if (MyAngle > 360) MyAngle = 90;  

            pictureBox1.Image = RotateImg(GetSourceImg(IMAGEFILE) MyAngle);

        }

        private void button2_Click(object sender EventArgs e)
        {
            MyAngle = 90;

            //MyAngle += -90;  

            //if (MyAngle < -360) MyAngle = -90;  

            //pictureBox1.Image = RotateImg(Bitmap.FromFile(IMAGEFILE) MyAngle);  

            pictureBox1.Image = RotateImg(IMAGEFILE MyAngle);
        }
        
       
            public Image RotateImg(Image b int angle)

        {

            angle = angle % 360;


            //弧度转换  

            double radian = angle * Math.PI / 180.0;

            double cos = Math.Cos(radian);

            double sin = Math.Sin(radian);


            //原图的宽和高  

            int w = b.Width;

            int h = b.Height;

            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin) Math.Abs(w * cos + h * sin)));

            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos) Math.Abs(w * sin + h * cos)));


            //目标位图  

            Bitmap dsImage = new Bitmap(W H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;


            //计算偏移量  

            Point Offset = new Point((W - w) / 2 (H - h) / 2);


            //构造图像显示区域:让图像的中心与窗口的中心点一致  

            Rectangle rect = new Rectangle(Offset.X Offset.Y w h);

            Point center = new Point(rect.X + rect.Width / 2 rect.Y + rect.Height / 2);


            g.TranslateTransform(center.X center.Y);

            g.RotateTransform(360 - angle);


            //恢复图像在水平和垂直方向的平移  

            g.TranslateTransform(-center.X -center.Y);

            g.DrawImage(b rect);


            //重至绘图的所有变换 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件         22  2019-01-08 00:19  WindowsFormsApp1\.git\COMMIT_EDITMSG

     文件        652  2019-01-08 00:19  WindowsFormsApp1\.git\config

     文件         73  2019-01-08 00:19  WindowsFormsApp1\.git\description

     文件         23  2019-01-08 00:19  WindowsFormsApp1\.git\HEAD

     文件        478  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\applypatch-msg.sample

     文件        896  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\commit-msg.sample

     文件        189  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\post-update.sample

     文件        424  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\pre-applypatch.sample

     文件       1642  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\pre-commit.sample

     文件       1348  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\pre-push.sample

     文件       4898  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\pre-rebase.sample

     文件        544  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\pre-receive.sample

     文件       1239  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\prepare-commit-msg.sample

     文件       3610  2019-01-08 00:19  WindowsFormsApp1\.git\hooks\update.sample

     文件       1342  2019-01-08 00:19  WindowsFormsApp1\.git\index

     文件        240  2019-01-08 00:19  WindowsFormsApp1\.git\info\exclude

     文件        342  2019-01-08 00:19  WindowsFormsApp1\.git\logs\HEAD

     文件        342  2019-01-08 00:19  WindowsFormsApp1\.git\logs\refs\heads\master

     文件        150  2019-01-08 00:19  WindowsFormsApp1\.git\ms-persist.xml

     文件        309  2019-01-08 00:19  WindowsFormsApp1\.git\objects\15\61dc464c42e1c9ee67b35eb0460758d39c8b2e

     文件        751  2019-01-08 00:19  WindowsFormsApp1\.git\objects\1f\f0c423042b46cb1d617b81efb715defbe8054d

     文件        186  2019-01-08 00:19  WindowsFormsApp1\.git\objects\25\ac2649af77613e96eae77f6030881daea5ee9a

     文件        186  2019-01-08 00:19  WindowsFormsApp1\.git\objects\39\645652af62950ebf3b28ec3a5400dcec30b1c4

     文件       2112  2019-01-08 00:19  WindowsFormsApp1\.git\objects\3c\4efe206bd0e7230ad0ae8396a3c883c8207906

     文件        491  2019-01-08 00:19  WindowsFormsApp1\.git\objects\43\8df21381ac484a2b9663978736c524d8e8f3bf

     文件        718  2019-01-08 00:19  WindowsFormsApp1\.git\objects\51\a5bb977d79c9e57ea68db6ead05a4bd98efc09

     文件        201  2019-01-08 00:19  WindowsFormsApp1\.git\objects\58\2c5bbdbf83bf24ef0fe768c23fb62986b509f8

     文件        163  2019-01-08 00:19  WindowsFormsApp1\.git\objects\5a\910188ecf4c3e80c90cdbf779e141f6bd565bf

     文件        460  2019-01-08 00:19  WindowsFormsApp1\.git\objects\7c\8a6772c734364efa0574cf1fd5ca54ab17e13b

     文件         89  2019-01-08 00:19  WindowsFormsApp1\.git\objects\91\e3470e1645e6e8d0de6fe9f6b242f366e9a393

............此处省略85个文件信息

评论

共有 条评论