728x90
반응형
728x170
using System.Drawing;
using System.Drawing.Drawing2D;
#region 복사하기 - Copy(sourceBitmap, squareSize)
/// <summary>
/// 복사하기
/// </summary>
/// <param name="sourceBitmap">소스 비트맵</param>
/// <param name="squareSize">정사각형 크기</param>
/// <returns>비트맵</returns>
public Bitmap Copy(Bitmap sourceBitmap, int squareSize)
{
float ratio = 1.0f;
int maximumSide = sourceBitmap.Width > sourceBitmap.Height ? sourceBitmap.Width : sourceBitmap.Height;
ratio = (float)maximumSide / (float)squareSize;
Bitmap targetBitmap;
if(sourceBitmap.Width > sourceBitmap.Height)
{
targetBitmap = new Bitmap(squareSize, (int)(sourceBitmap.Height / ratio));
}
else
{
targetBitmap = new Bitmap((int)(sourceBitmap.Width / ratio), squareSize);
}
using(Graphics targetGraphics = Graphics.FromImage(targetBitmap))
{
targetGraphics.CompositingQuality = CompositingQuality.HighQuality;
targetGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
targetGraphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
targetGraphics.DrawImage
(
sourceBitmap,
new Rectangle(0, 0, targetBitmap.Width, targetBitmap.Height),
new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height),
GraphicsUnit.Pixel
);
targetGraphics.Flush();
}
return targetBitmap;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Bitmap 클래스 : 경계 추출 필터(Boundary Extraction Filter) 사용하기 (0) | 2021.01.03 |
---|---|
[C#/WINFORM] Bitmap 클래스 : 카툰 필터(Cartoon Filter) 사용하기 (0) | 2021.01.03 |
[C#/WINFORM] Bitmap 클래스 : 오일 페인트 필터(Oil Paint Filter) 사용하기 (0) | 2021.01.03 |
[C#/WINFORM] Bitmap 클래스 : 이미지 추상 색상 필터 사용하기 (0) | 2021.01.03 |
[C#/WINFORM] Bitmap 클래스 : 바이트 배열 구하기 (0) | 2021.01.03 |
[C#/WINFORM] Bitmap 클래스 : 비트맵 일부 오버레이 표시하기 (0) | 2020.12.27 |
[C#/WINFORM] Bitmap 클래스 : 크기 변경 비트맵 구하기 (0) | 2020.12.27 |
[C#/WINFORM] Bitmap 클래스 : 비트맵 파일 로드하기 (0) | 2020.12.27 |
[C#/WINFORM] Application 클래스 : SetSuspendState 정적 메소드를 사용해 절전 모드 만들기 (0) | 2020.12.27 |
[C#/WINFORM] 지정 시간 경과 후 절전 모드에서 활성화하기 (0) | 2020.12.27 |
댓글을 달아 주세요