C#Image使用AForge.NET库进行旋转?

时间:2011-08-24 11:12:32

标签: c# .net image rotation aforge

为什么我的图像不会旋转?

    Image map = Properties.Resources.Map;

    //Creates a new Bitmap as the size of the window
    Bitmap bmp = new Bitmap(map.Width, map.Height);
    //Creates a new graphics to handle the image that is coming from the stream
    Graphics g = Graphics.FromImage((Image)bmp);
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

    MapY += (js.State.Y - 500)/100;
    MapRotation += (js.State.X - 500)/100;

    RotateBilinear filter = new RotateBilinear(30, true);
    g.DrawImage(map, 0, MapY, map.Width, map.Height);

    Bitmap newbmp = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);

    filter.Apply(newbmp);
    picBoxMap.Image = (Image)newbmp;

1 个答案:

答案 0 :(得分:3)

filter.Apply(newbmp) 

返回旋转图像的位图。

我的猜测是因为你没有分配新的位图,所以它会丢失。

尝试:

Bitmap rotatedBmp = filter.Apply(newbmp)

然后将rotateBmp用于您想要的任何内容。