c# 图片旋转问题

yiaosanba 2008-08-20 08:50:44
哪位大虾有c#写的图片按任意角度旋转的代码,能否共享一下,小弟急用,先谢啦
...全文
4094 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
youke_haoa 2012-07-08
  • 打赏
  • 举报
回复
mark备用
minddewo 2012-05-11
  • 打赏
  • 举报
回复
谢谢 找了好久 嘿嘿
morning_sunset 2011-10-19
  • 打赏
  • 举报
回复
what I want
Candy_Hui 2011-03-12
  • 打赏
  • 举报
回复
学习了
wzqiang1006 2010-08-11
  • 打赏
  • 举报
回复
很好,学习
sups851212 2010-04-11
  • 打赏
  • 举报
回复
受教啦
安卓er 2009-04-19
  • 打赏
  • 举报
回复
很好很强大,我收下了哦
brouse130 2008-08-22
  • 打赏
  • 举报
回复
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;
}

}
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;
}


.TranslateTransform(-Pcenter.X, -Pcenter.Y);
g.DrawImage(temp, x, y, w, h);
g.ResetTransform();
return userimage;




GZBG2008 2008-08-20
  • 打赏
  • 举报
回复
学习中
萱哥老了 2008-08-20
  • 打赏
  • 举报
回复
收藏
优途科技 2008-08-20
  • 打赏
  • 举报
回复
            Bitmap userimage=Image.FromImage("要旋转的图片的路径"); 
Graphics g = Graphics.FromImage(userimage);//userimage是要旋转的图片
PointF Pcenter = new PointF(userimage.Width / 2, userimage.Height / 2);//Pcenter是中心点
g.TranslateTransform(Pcenter.X, Pcenter.Y);
g.RotateTransform(Rotate);//Rotate是要旋转的角度
g.TranslateTransform(-Pcenter.X, -Pcenter.Y);
g.DrawImage(temp, x, y, w, h);//x,y,w,h代表左上角的x点坐标,y点坐标,图片的宽和高
g.ResetTransform();
return userimage;
mawering 2008-08-20
  • 打赏
  • 举报
回复
Bitmap userimage=Image.FromImage("要旋转的图片的路径");
Graphics g = Graphics.FromImage(userimage);//userimage是要旋转的图片
PointF Pcenter = new PointF(userimage.Width / 2, userimage.Height / 2);//Pcenter是中心点
g.TranslateTransform(Pcenter.X, Pcenter.Y);
g.RotateTransform(Rotate);//Rotate是要旋转的角度
g.TranslateTransform(-Pcenter.X, -Pcenter.Y);
g.DrawImage(temp, x, y, w, h);//x,y,w,h代表左上角的x点坐标,y点坐标,图片的宽和高
g.ResetTransform();
return userimage;
pp_shy 2008-08-20
  • 打赏
  • 举报
回复
再见品月 2008-08-20
  • 打赏
  • 举报
回复
Mark .学习
nyq1011 2008-08-20
  • 打赏
  • 举报
回复
学习!
cc8364 2008-08-20
  • 打赏
  • 举报
回复
学习
宝_爸 2008-08-20
  • 打赏
  • 举报
回复
旋转任意角度来了

/// <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;
}
whycom 2008-08-20
  • 打赏
  • 举报
回复
e.Graphics.RotateTransform((float)30.0);
Image image = Image.FromFile("xxxx.jpg ");
e.Graphics.DrawImage(image, new Point(0, 0));
宝_爸 2008-08-20
  • 打赏
  • 举报
回复
好像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;
}

}
amingo 2008-08-20
  • 打赏
  • 举报
回复
帮顶~!~~~`

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧