C# c语言中的旋转图形/图像#

C# c语言中的旋转图形/图像#,c#,graphics,bitmap,rotation,C#,Graphics,Bitmap,Rotation,我写了下面的代码来尝试旋转一个位图(这是一个测试)。这个想法是将一个位图旋转一定的角度,然后使用win窗体在屏幕上绘制它 protected override void OnDoubleClick(EventArgs e) { base.OnDoubleClick(e); Graphics g = this.CreateGraphics(); Bitmap b = new Bitmap(path); g.Clear(Colo

我写了下面的代码来尝试旋转一个位图(这是一个测试)。这个想法是将一个位图旋转一定的角度,然后使用win窗体在屏幕上绘制它

protected override void OnDoubleClick(EventArgs e)
    {
        base.OnDoubleClick(e);
        Graphics g = this.CreateGraphics();
        Bitmap b = new Bitmap(path);
        g.Clear(Color.White);
        imagePosition = Cursor.Position;
        b = RotateImage(b, 45);
        g.DrawImage(b, new Point(100, 100));
    }
    public Bitmap RotateImage(Bitmap b, float angle)
    {
        Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
        returnBitmap.SetResolution(b.HorizontalResolution, b.VerticalResolution);
        Graphics g = Graphics.FromImage(returnBitmap);
        g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
        g.RotateTransform(angle);
        g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
        g.DrawImage(b, new Point(0, 0));
        return returnBitmap;
    }
这是旋转前的图像

这是旋转45度后的图像,如代码所示
它被剪裁的原因是没有足够的空间显示它。对角线比边长(毕达哥拉斯)


您需要为图像留出更多空间,然后它应该显示OK。如何操作将取决于图像所包含的内容。

有什么问题?是图像被剪了吗?我想是的,但我不知道为什么我一开始不明白这个问题,是的,问题是图像被剪了