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.Drawing.Drawing2D;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(pictureBox1.ClientRectangle);
Region region = new Region(gp);
pictureBox1.Region = region;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image=Rotate(pictureBox1.Image, 45);
}
public Image Rotate(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);
Graphics g = Graphics.FromImage(dsImage);
g.InterpolationMode = InterpolationMode.Bilinear;
g.SmoothingMode = 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);
g.ResetTransform();
g.Save();
g.Dispose();
return dsImage;
}
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = Rotate(pictureBox1.Image, 90);
}
}
}
uj5u.com熱心網友回復:
你這張圖有多大(像素數)?影像旋轉時使用整數運算會帶來舍入誤差,如果影像本來就不大,那么多次運算帶來的總誤差就大了。uj5u.com熱心網友回復:
https://bbs.csdn.net/topics/395656234的2樓
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
樓上6幅圖360度轉還不夠耍的?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/76324.html
標籤:C#
上一篇:如果是旋轉90度的倍數可以,其他的角度圖片會變小,怎么解決
下一篇:可以收放的選單怎么做
