■ Bitmap 클래스 : 비트맵 회전하기

------------------------------------------------------------------------------------------------------------------------

using System.Drawing;

using System.Drawing.Drawing2D;

 

#region 비트맵 회전하기 - RotateBitmap(sourceBitmap, angle)

 

/// <summary>

/// 비트맵 회전하기

/// </summary>

/// <param name="sourceBitmap">소스 비트맵</param>

/// <param name="angle">각도</param>

/// <returns>회전 비트맵</returns>

public Bitmap RotateBitmap(Bitmap sourceBitmap, double angle)

{

    Bitmap targetBitmap = new Bitmap(sourceBitmap.Width, sourceBitmap.Height);

 

    using(Graphics graphics = Graphics.FromImage(targetBitmap))

    {

        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

 

        graphics.TranslateTransform(sourceBitmap.Width / 2, sourceBitmap.Height / 2);

 

        graphics.RotateTransform(-(float)angle);

 

        graphics.DrawImage

        (

            sourceBitmap,

            -sourceBitmap.Width  / 2,

            -sourceBitmap.Height / 2,

            sourceBitmap.Width,

            sourceBitmap.Height

        );

    }

 

    return targetBitmap;

}

 

#endregion

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요