4个回答
展开全部
public static Bitmap KiRotate90(Bitmap img)
...{
try
...{
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
return img;
}
catch
...{
return null;
}
}
很容易就看出来,关键在于RotateFlipType参数。
实践结果如下:
顺时针旋转90度 RotateFlipType.Rotate90FlipNone
逆时针旋转90度 RotateFlipType.Rotate270FlipNone
水平翻转 RotateFlipType.Rotate180FlipY
垂直翻转 RotateFlipType.Rotate180FlipX
...{
try
...{
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
return img;
}
catch
...{
return null;
}
}
很容易就看出来,关键在于RotateFlipType参数。
实践结果如下:
顺时针旋转90度 RotateFlipType.Rotate90FlipNone
逆时针旋转90度 RotateFlipType.Rotate270FlipNone
水平翻转 RotateFlipType.Rotate180FlipY
垂直翻转 RotateFlipType.Rotate180FlipX
参考资料: http://www.cnblogs.com/cai9911/archive/2007/09/28/909111.html
展开全部
/// <summary>
/// 向左旋转90度
/// </summary>
/// <param name="img">图片对象</param>
/// <returns></returns>
private Bitmap KiRotateLeft(Bitmap img)
{
try
{
img.RotateFlip(RotateFlipType.Rotate270FlipNone);
return img;
}
catch
{
return null;
}
}
/// <summary>
/// 向右旋转90度
/// </summary>
/// <param name="img">图片对象</param>
/// <returns></returns>
private Bitmap KiRotateRight(Bitmap img)
{
try
{
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
return img;
}
catch
{
return null;
}
}
/// <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)
{
try
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
System.Drawing.Imaging.PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = System.Drawing.Imaging.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();
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.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 = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
catch
{
return null;
}
}
/// 向左旋转90度
/// </summary>
/// <param name="img">图片对象</param>
/// <returns></returns>
private Bitmap KiRotateLeft(Bitmap img)
{
try
{
img.RotateFlip(RotateFlipType.Rotate270FlipNone);
return img;
}
catch
{
return null;
}
}
/// <summary>
/// 向右旋转90度
/// </summary>
/// <param name="img">图片对象</param>
/// <returns></returns>
private Bitmap KiRotateRight(Bitmap img)
{
try
{
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
return img;
}
catch
{
return null;
}
}
/// <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)
{
try
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
System.Drawing.Imaging.PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = System.Drawing.Imaging.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();
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.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 = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
catch
{
return null;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public
static
Bitmap
KiRotate90(Bitmap
img)
...{
try
...{
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
return
img;
}
catch
...{
return
null;
}
}
很容易就看出来,关键在于RotateFlipType参数。
实践结果如下:
顺时针旋转90度
RotateFlipType.Rotate90FlipNone
逆时针旋转90度
RotateFlipType.Rotate270FlipNone
水平翻转
RotateFlipType.Rotate180FlipY
垂直翻转
RotateFlipType.Rotate180FlipX
static
Bitmap
KiRotate90(Bitmap
img)
...{
try
...{
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
return
img;
}
catch
...{
return
null;
}
}
很容易就看出来,关键在于RotateFlipType参数。
实践结果如下:
顺时针旋转90度
RotateFlipType.Rotate90FlipNone
逆时针旋转90度
RotateFlipType.Rotate270FlipNone
水平翻转
RotateFlipType.Rotate180FlipY
垂直翻转
RotateFlipType.Rotate180FlipX
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把显示器转过来。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |