相关疑难解决方法(0)

如何在c#中旋转图像x度?

我做了一些搜索,我找不到任何功能,做我想做的事情.

我有一个带有文本的扫描文档的图像文件,但是文档旋转了一些度数,因此我想旋转它以使文本彼此内联.

在一个完美的世界中,它应该是一个自动执行此功能的功能,但我无法找到任何东西和我理解的自动工作,它需要对图像进行一些分析,我认为它是大事.

但后来我已经做了一个工具来手动旋转网站上的图像,但现在我需要一个功能来保存旋转到图像文件.

这似乎是一些不同的方法,但没有人我测试做我想做的.

我发现的功能几乎就像我的作品一样:

public static Bitmap RotateImg(Bitmap bmp, float angle, Color bkColor) {
int w = bmp.Width;
int h = bmp.Height;
PixelFormat pf = default(PixelFormat);
if (bkColor == Color.Transparent)
{
    pf = PixelFormat.Format32bppArgb;
}
else
{
    pf = bmp.PixelFormat;
}

Bitmap tempImg = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tempImg);
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();
//Using System.Drawing.Drawing2D.Matrix class 
mtrx.Rotate(angle);
RectangleF rct …
Run Code Online (Sandbox Code Playgroud)

c# graphics drawing image

12
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

drawing ×1

graphics ×1

image ×1