资源简介
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\desc
文件 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-reba
文件 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.xm
文件 309 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 751 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 186 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 186 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 2112 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 491 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 718 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 201 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 163 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 460 2019-01-08 00:19 WindowsFormsApp1\.git\ob
文件 89 2019-01-08 00:19 WindowsFormsApp1\.git\ob
............此处省略85个文件信息
- 上一篇:C#语言的网络爬虫
- 下一篇:C#6.0学习笔记随书代码
相关资源
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
评论
共有 条评论