日期:2014-05-18  浏览次数:20872 次

c# 图片旋转问题
哪位大虾有c#写的图片按任意角度旋转的代码,能否共享一下,小弟急用,先谢啦

------解决方案--------------------
帮顶~!~~~`
------解决方案--------------------
好像Image只能转90,180,270

Bitmap bitmap1;

private void InitializeBitmap()
{
try
{
bitmap1 = (Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\" + 
@"All Users\Documents\My Music\music.bmp");
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
PictureBox1.Image = bitmap1;
}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("There was an error." + 
"Check the path to the bitmap.");
}


}

private void Button1_Click(System.Object sender, System.EventArgs e)
{

if (bitmap1 != null)
{
bitmap1.RotateFlip(RotateFlipType.Rotate180FlipY);
PictureBox1.Image = bitmap1;
}

}

------解决方案--------------------
e.Graphics.RotateTransform((float)30.0);
Image image = Image.FromFile("xxxx.jpg ");
e.Graphics.DrawImage(image, new Point(0, 0));
------解决方案--------------------
旋转任意角度来了

/// <summary>
/// 任意角度旋转
/// </summary>
/// <param name="bmp">原始图Bitmap</param>
/// <param name="angle">旋转角度</param>
/// <param name="bkColor">背景色</param>
/// <returns>输出Bitmap</returns>
public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor)
...{
int w = bmp.Width + 2;
int h = bmp.Height + 2;

PixelFormat pf;

if (bkColor == Color.Transparent)
...{
pf = PixelFormat.Format32bppArgb;
}
else
...{
pf = bmp.PixelFormat;
}

Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();

GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);
RectangleF rct = path.GetBounds(mtrx);

Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();

tmp.Dispose();

return dst;
}

------解决方案--------------------
学习
------解决方案--------------------
学习!
------解决方案--------------------
Mark .学习
------解决方案--------------------
任意角度旋转
http://topic.csdn.net/u/20080703/22/97cf7963-a3dc-4051-a917-a2b92f6c6abc.html
1楼我的回答
------解决方案--------------------
Bitmap userimage=Image.FromImage("要旋转的图片的路径");
Graphics g = Graphics.FromImage(userimage);//userimage是要旋转的图片