求帮忙编个 指南针 4天了哭死 额 请各位大大帮个忙 C#编个 指南针要求 根据输入量能够旋转角度。。之前 我的思想是 用个png格式的指南针图片做个图片旋转就是了但是 做不出来啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 gdi+ 画线,只要懂角度以及弧度和坐标的概念即可。google下 c# gdi+ GDI+我之前做的一个时钟,看能给你参看不http://hi.baidu.com/jiang_yy_jiang/blog/item/467aa6816fb86bd5bd3e1ee2.html Image的旋转,下面的页面有源代码。我用过,挺好使的。C# Image Rotatehttp://www.vcskicks.com/image-rotate.php ??我这里能访问啊。我直接贴相关代码算了看RotateImage函数和PointMath类//====================================================//| Downloaded From |//| Visual C# Kicks - http://www.vcskicks.com/ |//| License - http://www.vcskicks.com/license.html |//====================================================using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.IO;using System.Text;using System.Windows.Forms;namespace ImageRotation{ public partial class Form1 : Form { private Image loadedImage; public Form1() { InitializeComponent(); } private Image RotateImage(Image inputImg, double degreeAngle) { //Corners of the image PointF[] rotationPoints = { new PointF(0, 0), new PointF(inputImg.Width, 0), new PointF(0, inputImg.Height), new PointF(inputImg.Width, inputImg.Height)}; //Rotate the corners PointF centerPoint = new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f); PointMath.PointMath.RotatePoints(ref rotationPoints, ref centerPoint, ref degreeAngle); //Get the new bounds given from the rotation of the corners //(avoid clipping of the image) Rectangle bounds = PointMath.PointMath.GetBounds(ref rotationPoints); //An empy bitmap to draw the rotated image Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height); using (Graphics g = Graphics.FromImage(rotatedBitmap)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; //Transformation matrix Matrix m = new Matrix(); m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f)); m.Translate(-bounds.Left, -bounds.Top, MatrixOrder.Append); //shift to compensate for the rotation g.Transform = m; g.DrawImage(inputImg, 0, 0); } return (Image)rotatedBitmap; } private void trackBar1_Scroll(object sender, EventArgs e) { if (loadedImage != null) pictureBox1.Image = RotateImage(loadedImage, (double)tRotation.Value); pictureBox1.Refresh(); } private void btnLoad_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { loadedImage = Image.FromFile(openFileDialog1.FileName); pictureBox1.Image = loadedImage; //Reset rotation value tRotation.Value = 0; } catch (Exception) { MessageBox.Show("Image invalid."); } } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.vcskicks.com/"); } } public static class PointMath { private static double DegreeToRadian(double angle) { return Math.PI * angle / 180.0; } public static PointF RotatePoint(PointF pnt, double degreeAngle) { return RotatePoint(pnt, new PointF(0, 0), degreeAngle); } public static PointF RotatePoint(PointF pnt, PointF origin, double degreeAngle) { double radAngle = DegreeToRadian(degreeAngle); PointF newPoint = new PointF(); double deltaX = pnt.X - origin.X; double deltaY = pnt.Y - origin.Y; newPoint.X = (float)(origin.X + (Math.Cos(radAngle) * deltaX - Math.Sin(radAngle) * deltaY)); newPoint.Y = (float)(origin.Y + (Math.Sin(radAngle) * deltaX + Math.Cos(radAngle) * deltaY)); return newPoint; } public static void RotatePoints(PointF[] pnts, double degreeAngle) { for (int i = 0; i < pnts.Length; i++) { pnts[i] = RotatePoint(pnts[i], degreeAngle); } } public static void RotatePoints(PointF[] pnts, PointF origin, double degreeAngle) { for (int i = 0; i < pnts.Length; i++) { pnts[i] = RotatePoint(pnts[i], origin, degreeAngle); } } public static Rectangle GetBounds(PointF[] pnts) { RectangleF boundsF = GetBoundsF(pnts); return new Rectangle((int)Math.Round(boundsF.Left), (int)Math.Round(boundsF.Top), (int)Math.Round(boundsF.Width), (int)Math.Round(boundsF.Height)); } public static RectangleF GetBoundsF(PointF[] pnts) { float left = pnts[0].X; float right = pnts[0].X; float top = pnts[0].Y; float bottom = pnts[0].Y; for (int i = 1; i < pnts.Length; i++) { if (pnts[i].X < left) left = pnts[i].X; else if (pnts[i].X > right) right = pnts[i].X; if (pnts[i].Y < top) top = pnts[i].Y; else if (pnts[i].Y > bottom) bottom = pnts[i].Y; } return new RectangleF(left, top, (float)Math.Abs(right - left), (float)Math.Abs(bottom - top)); } }} 唉,请忽略我10楼的回复。里面有我加的测试代码,我上传没有修改的代码到csdn下载了。请从这里下载http://download.csdn.net/source/3026466 http://www.codeproject.com/KB/graphics/rotateimage.aspx 求助怎么设置使得excel表格能够嵌入winform中 求一个方案的声音合并的解决方案 单用户模式 按照特定的顺序得到一个文件夹里面的所有文件 水晶报表制作问题? 关于线程池 怎么使用这个彩铃接口?!课程设计!很急啊 SOS,请前辈帮我看看 动态Radiobuttonlist 这是什么破玩意! 百分比只能输入两位小数的的正则表达式怎么弄? 很简单的问题
google下 c# gdi+
http://hi.baidu.com/jiang_yy_jiang/blog/item/467aa6816fb86bd5bd3e1ee2.html
http://www.vcskicks.com/image-rotate.php
我直接贴相关代码算了
看RotateImage函数和PointMath类//====================================================
//| Downloaded From |
//| Visual C# Kicks - http://www.vcskicks.com/ |
//| License - http://www.vcskicks.com/license.html |
//====================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using System.Windows.Forms;namespace ImageRotation
{
public partial class Form1 : Form
{
private Image loadedImage; public Form1()
{
InitializeComponent();
} private Image RotateImage(Image inputImg, double degreeAngle)
{
//Corners of the image
PointF[] rotationPoints = { new PointF(0, 0),
new PointF(inputImg.Width, 0),
new PointF(0, inputImg.Height),
new PointF(inputImg.Width, inputImg.Height)}; //Rotate the corners
PointF centerPoint = new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f);
PointMath.PointMath.RotatePoints(ref rotationPoints, ref centerPoint, ref degreeAngle); //Get the new bounds given from the rotation of the corners
//(avoid clipping of the image)
Rectangle bounds = PointMath.PointMath.GetBounds(ref rotationPoints); //An empy bitmap to draw the rotated image
Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height); using (Graphics g = Graphics.FromImage(rotatedBitmap))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic; //Transformation matrix
Matrix m = new Matrix();
m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f));
m.Translate(-bounds.Left, -bounds.Top, MatrixOrder.Append); //shift to compensate for the rotation g.Transform = m;
g.DrawImage(inputImg, 0, 0);
} return (Image)rotatedBitmap;
} private void trackBar1_Scroll(object sender, EventArgs e)
{
if (loadedImage != null)
pictureBox1.Image = RotateImage(loadedImage, (double)tRotation.Value);
pictureBox1.Refresh();
} private void btnLoad_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
loadedImage = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = loadedImage; //Reset rotation value
tRotation.Value = 0;
}
catch (Exception)
{
MessageBox.Show("Image invalid.");
}
}
} private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.vcskicks.com/");
}
} public static class PointMath
{
private static double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
} public static PointF RotatePoint(PointF pnt, double degreeAngle)
{
return RotatePoint(pnt, new PointF(0, 0), degreeAngle);
} public static PointF RotatePoint(PointF pnt, PointF origin, double degreeAngle)
{
double radAngle = DegreeToRadian(degreeAngle); PointF newPoint = new PointF(); double deltaX = pnt.X - origin.X;
double deltaY = pnt.Y - origin.Y; newPoint.X = (float)(origin.X + (Math.Cos(radAngle) * deltaX - Math.Sin(radAngle) * deltaY));
newPoint.Y = (float)(origin.Y + (Math.Sin(radAngle) * deltaX + Math.Cos(radAngle) * deltaY)); return newPoint;
} public static void RotatePoints(PointF[] pnts, double degreeAngle)
{
for (int i = 0; i < pnts.Length; i++)
{
pnts[i] = RotatePoint(pnts[i], degreeAngle);
}
} public static void RotatePoints(PointF[] pnts, PointF origin, double degreeAngle)
{
for (int i = 0; i < pnts.Length; i++)
{
pnts[i] = RotatePoint(pnts[i], origin, degreeAngle);
}
} public static Rectangle GetBounds(PointF[] pnts)
{
RectangleF boundsF = GetBoundsF(pnts);
return new Rectangle((int)Math.Round(boundsF.Left),
(int)Math.Round(boundsF.Top),
(int)Math.Round(boundsF.Width),
(int)Math.Round(boundsF.Height));
} public static RectangleF GetBoundsF(PointF[] pnts)
{
float left = pnts[0].X;
float right = pnts[0].X;
float top = pnts[0].Y;
float bottom = pnts[0].Y; for (int i = 1; i < pnts.Length; i++)
{
if (pnts[i].X < left)
left = pnts[i].X;
else if (pnts[i].X > right)
right = pnts[i].X; if (pnts[i].Y < top)
top = pnts[i].Y;
else if (pnts[i].Y > bottom)
bottom = pnts[i].Y;
} return new RectangleF(left,
top,
(float)Math.Abs(right - left),
(float)Math.Abs(bottom - top));
}
}
}
里面有我加的测试代码,我上传没有修改的代码到csdn下载了。
请从这里下载http://download.csdn.net/source/3026466