C#绘图正常是不涉及到旋转的。有时候会有旋转画笔的情况。比如条码打印字竖着打印。旋转图片一定角度绘制。或者斜着画水印。这时候就涉及到旋转画笔了。
源码地址
通过graphics.TranslateTransform(Pcenter.X, Pcenter.Y);设置旋转的中心坐标。通过graphics.RotateTransform(i%360);设置画笔的旋转角度。
参照示例:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace 图片操作
{
public partial class Form1 : Form
{
bool a = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(旋转));
thread.Start();
}
private void 旋转()
{
#region MyRegion
Graphics graphics = this.CreateGraphics();
graphics.Clear(Color.White);
Bitmap image = new Bitmap("1.bmp");
RectangleF picRect = new RectangleF(100, 100, image.Width, image.Height);
PointF Pcenter = new PointF(picRect.X + picRect.Width / 2,
picRect.Y + picRect.Height / 2);
#endregion
for (int i = 0;; i += 5)
{
graphics.TranslateTransform(Pcenter.X, Pcenter.Y);
graphics.RotateTransform(i%360);
graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y);
graphics.DrawImage(image, picRect);
Thread.Sleep(50);
graphics.ResetTransform();
if (a)
{
break;
}
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
a = true;
Application.Exit();
}
}
}
代码的效果就是把.net图标不停的360度旋转
供需要绘图的同学参考
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)