資源簡介
c#圖像旋轉,加工后可以用來顯示進度狀態(tài)等信息,或者其他需要旋轉圖像的地方

代碼片段和文件信息
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?圖像旋轉
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????}
????????Timer?timer1;//定時旋轉和移動
????????Graphics?g;//背景圖的畫圖對象
????????float?x?=?0;//水平移動的初始位置
????????Bitmap?bmp;
????????Bitmap?background;
????????private?void?pictureBox1_Click(object?sender?EventArgs?e)
????????{
????????????//OpenFileDialog?opf?=?new??OpenFileDialog();
????????????//if?(opf.ShowDialog()?!=?System.Windows.Forms.DialogResult.OK)
????????????//????return;
????????????//bmp?=?new?Bitmap(opf.FileName?);
????????????//background?=?new?Bitmap(pictureBox1.Width?pictureBox1.Height?System.Drawing.Imaging.PixelFormat.Format24bppRgb);//畫在PictureBox上
????????????//g?=?Graphics.FromImage(background);
????????????//g.TranslateTransform(background.Width?/?2?background.Height?/?2);//移動一下中心點,畫在背景的中央,好看些
????????????//timer1?=?new?Timer();
????????????//timer1.Interval?=?100;
????????????//timer1.Tick?+=?new?EventHandler(timer1_Tick);
????????????//timer1.Enabled?=?true;
????????}
????????void?timer1_Tick(object?sender?EventArgs?e)
????????{
????????????g.Clear(Color.Black);
????????????g.RotateTransform(10.0F);//每次旋轉10度,實際上是畫圖坐標旋轉
????????????g.DrawImage(bmp?-bmp.Width?/?2?-bmp.Height?/?2);//源圖中心點和畫圖對象中心重合,自旋轉效果,否則會以左上角為中心旋轉
????????????Graphics?gb?=?pictureBox1.CreateGraphics();
????????????x?+=?3.0f;//水平移動效果,步長3像素
????????????pictureBox1.Refresh();
????????}
????????//任意角度旋轉
????????private?void?RotateTransformButton_Click(object?sender?EventArgs?e)
????????{
????????????try
????????????{
????????????????//Bitmap?a?=?new?Bitmap(pictureBox1.Image);//得到圖片框中的圖片
????????????????//pictureBox1.Image?=?Rotate(a?Convert.ToInt32(textBox1.Text));
????????????????//pictureBox1.SizeMode?=?PictureBoxSizeMode.AutoSize;
????????????????//pictureBox1.Location?=?panel1.Location;
????????????????//pictureBox1.Refresh();//最后刷新圖片框
????????????}
????????????catch?{?}
????????}
????????#region?圖片旋轉函數
????????///?
????????///?以逆時針為方向對圖像進行旋轉
????????///?
????????///?位圖流
????????///?旋轉角度[0360](前臺給的)
????????///?
????????public?Bitmap?Rotate(Bitmap?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?=?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????878??2014-08-13?14:07??圖像旋轉.sln
????..A..H.?????19456??2014-08-15?18:30??圖像旋轉.suo
?????文件??????11264??2014-08-13?14:45??圖像旋轉\bin\Debug\圖像旋轉.exe
?????文件??????28160??2014-08-13?14:45??圖像旋轉\bin\Debug\圖像旋轉.pdb
?????文件??????11600??2014-08-15?10:18??圖像旋轉\bin\Debug\圖像旋轉.vshost.exe
?????文件????????490??2012-06-06?02:06??圖像旋轉\bin\Debug\圖像旋轉.vshost.exe.manifest
?????文件???????5609??2014-08-13?14:45??圖像旋轉\Form1.cs
?????文件???????4548??2014-08-13?14:45??圖像旋轉\Form1.Designer.cs
?????文件???????6011??2014-08-13?14:45??圖像旋轉\Form1.resx
?????文件???????5420??2014-08-15?10:10??圖像旋轉\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6417??2014-08-13?14:45??圖像旋轉\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????813??2014-08-15?10:18??圖像旋轉\obj\x86\Debug\圖像旋轉.csproj.FileListAbsolute.txt
?????文件????????975??2014-08-13?14:45??圖像旋轉\obj\x86\Debug\圖像旋轉.csproj.GenerateResource.Cache
?????文件??????11264??2014-08-13?14:45??圖像旋轉\obj\x86\Debug\圖像旋轉.exe
?????文件????????180??2014-08-13?14:45??圖像旋轉\obj\x86\Debug\圖像旋轉.Form1.resources
?????文件??????28160??2014-08-13?14:45??圖像旋轉\obj\x86\Debug\圖像旋轉.pdb
?????文件????????180??2014-08-13?14:12??圖像旋轉\obj\x86\Debug\圖像旋轉.Properties.Resources.resources
?????文件????????493??2014-08-13?14:07??圖像旋轉\Program.cs
?????文件???????1356??2014-08-13?14:07??圖像旋轉\Properties\AssemblyInfo.cs
?????文件???????2876??2014-08-13?14:07??圖像旋轉\Properties\Resources.Designer.cs
?????文件???????5612??2014-08-13?14:07??圖像旋轉\Properties\Resources.resx
?????文件???????1099??2014-08-13?14:07??圖像旋轉\Properties\Settings.Designer.cs
?????文件????????249??2014-08-13?14:07??圖像旋轉\Properties\Settings.settings
?????文件???????3683??2014-08-13?14:12??圖像旋轉\圖像旋轉.csproj
?????目錄??????????0??2014-08-13?14:07??圖像旋轉\obj\x86\Debug\TempPE
?????目錄??????????0??2014-08-15?10:10??圖像旋轉\obj\x86\Debug
?????目錄??????????0??2014-08-13?14:12??圖像旋轉\bin\Debug
?????目錄??????????0??2014-08-13?14:07??圖像旋轉\obj\x86
?????目錄??????????0??2014-08-13?14:07??圖像旋轉\bin
?????目錄??????????0??2014-08-13?14:07??圖像旋轉\obj
............此處省略5個文件信息
評論
共有 條評論