Home > Net >  How to set up the image rotation at any Angle but size remains the same. Use this program to debug t
How to set up the image rotation at any Angle but size remains the same. Use this program to debug t

Time:09-23

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;

The namespace test
{
Public partial class Form1: Form
{
Public _click ()
{
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 of=% 360;
Double radian Angle of=* Math. PI/180.0;
Double cosine=Math. Cos (radian);
A double sin=Math. Sin (radian);
=b.W int w idth;
Int h=b.H eight;
Int W=(int) (Math. Max (Math. Abs (cos - h * W * sin), Math. Abs (cos + h W * * sin)));
Int H=(int) (Math. Max (Math. Abs (sin - H * w * cos), Math. Abs (sin cos + H * w *)));
Bitmap dsImage=new Bitmap (W, H);
Graphics g=Graphics. FromImage (dsImage);
G.I nterpolationMode=InterpolationMode. Bilinear;
G.S moothingMode=SmoothingMode. HighQuality;
Point Offset=new Point ((W - W)/2, (H - H)/2);
A Rectangle the rect=new Rectangle (Offset. X, Offset.. Y, w, h);
Point center=new Point (the rect. X + the rect. Width/2, the rect. Y + the rect. Height/2);
G.T ranslateTransform (center. X, center. Y);
G.R otateTransform (360 - Angle);
G.T ranslateTransform - center. X - center. (Y);
G.D rawImage (b, the rect);
G.R esetTransform ();
G.S ave ();
G.D ispose ();
Return dsImage;
}

Private void timer1_Tick (object sender, EventArgs e)
{
PictureBox1. Image=Rotate (pictureBox1. Image, 90);
}
}
}

CodePudding user response:

How big is this picture you (number)? When the image rotation using integer arithmetic rounding error, if the image is not big, so many times operation of total error is big,

CodePudding user response:

https://bbs.csdn.net/topics/395656234
The second floor

CodePudding user response:

CodePudding user response:

The
reference 3 floor weixin_43451707 response:

6 picture above 360 degrees turn enough play?
  •  Tags:  
  • C #
  • Related