첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170
using System.Drawing;
using System.Drawing.Drawing2D;

#region 비트맵 구하기 - GetBitmap(sourceBitmap, targetWidth)

/// <summary>
/// 비트맵 구하기
/// </summary>
/// <param name="sourceBitmap">소스 비트맵</param>
/// <param name="targetWidth">타겟 너비</param>
/// <returns>비트맵</returns>
public Bitmap GetBitmap(Bitmap sourceBitmap, int targetWidth)
{
    float ratio = 1.0f;

    int maximumSide = sourceBitmap.Width > sourceBitmap.Height ? sourceBitmap.Width : sourceBitmap.Height;

    ratio = (float)maximumSide / (float)targetWidth;

    Bitmap targetBitmap =
    (
        sourceBitmap.Width > sourceBitmap.Height ?
            new Bitmap(targetWidth, (int)(sourceBitmap.Height / ratio)) :
            new Bitmap((int)(sourceBitmap.Width / ratio), targetWidth)
    );

    using(Graphics graphics = Graphics.FromImage(targetBitmap))
    {
        graphics.CompositingQuality = CompositingQuality.HighQuality;
        graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
        graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;

        graphics.DrawImage
        (
            sourceBitmap,
            new Rectangle(0, 0, targetBitmap.Width, targetBitmap.Height),
            new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height),
            GraphicsUnit.Pixel
        );

        graphics.Flush();
    }

    return targetBitmap;
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요