using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
Load += Form_Load;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
Bitmap size16Bitmap = GetSize16Bitmap();
Bitmap size24Bitmap = GetSize24Bitmap();
Bitmap size32Bitmap = GetSize32Bitmap();
Bitmap size48Bitmap = GetSize48Bitmap();
Bitmap size256Bitmap = GetSize256Bitmap();
this.size16PictureBox.Image = size16Bitmap;
this.size24PictureBox.Image = size24Bitmap;
this.size32PictureBox.Image = size32Bitmap;
this.size48PictureBox.Image = size48Bitmap;
this.size256PictureBox.Image = size256Bitmap;
Bitmap[] bitmapArray =
{
size16Bitmap,
size32Bitmap,
size24Bitmap,
size48Bitmap,
size256Bitmap
};
string filePath = "D:\\result.ico";
IconHelper.Save(bitmapArray, filePath, true);
Icon = IconHelper.Save(bitmapArray);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 크기 16 비트맵 구하기 - GetSize16Bitmap()
/// <summary>
/// 크기 16 비트맵 구하기
/// </summary>
/// <returns>크기 16 비트맵</returns>
private Bitmap GetSize16Bitmap()
{
const int width = 16;
const int height = 16;
Bitmap bitmap = new Bitmap(width, height);
using(Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
graphics.Clear(Color.Transparent);
const int thickness = 1;
using(Pen pen = new Pen(Color.Blue, thickness))
{
RectangleF rectangle = new RectangleF
(
thickness / 2f,
thickness / 2f,
width - thickness,
height - thickness
);
graphics.FillRectangle(Brushes.Blue, rectangle);
graphics.DrawRectangle(pen, rectangle);
}
using(StringFormat stringFormat = new StringFormat())
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
const float fontSize = 6;
using(Font font = new Font("Arial", fontSize, FontStyle.Bold))
{
float centerX = width / 2f;
float y1 = height / 3f;
float y3 = height / 3f * 2;
const float fontScale = 1f;
GraphicsState state = graphics.Save();
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(centerX, y1, MatrixOrder.Append);
graphics.DrawString("S", font, Brushes.White, 0, 0, stringFormat);
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(centerX, y3, MatrixOrder.Append);
graphics.DrawString("I", font, Brushes.White, 0, 0, stringFormat);
graphics.Restore(state);
}
}
}
return bitmap;
}
#endregion
#region 크기 24 비트맵 구하기 - GetSize24Bitmap()
/// <summary>
/// 크기 24 비트맵 구하기
/// </summary>
/// <returns>크기 24 비트맵</returns>
private Bitmap GetSize24Bitmap()
{
const int width = 24;
const int height = 24;
Bitmap bitmap = new Bitmap(width, height);
using(Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
graphics.Clear(Color.Transparent);
const int thickness = 1;
using(Pen pen = new Pen(Color.Blue, thickness))
{
RectangleF rectangle = new RectangleF
(
thickness / 2f,
thickness / 2f,
width - thickness,
height - thickness
);
graphics.FillRectangle(Brushes.Blue, rectangle);
graphics.DrawRectangle(pen, rectangle);
}
using(StringFormat stringFormat = new StringFormat())
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
const float fontSize = 10;
using(Font font = new Font("Times New Roman", fontSize, FontStyle.Bold))
{
float x1 = width / 3f;
float x3 = width / 3f * 2;
float y1 = height / 3f;
float y3 = height / 3f * 2;
const float fontScale = 1f;
GraphicsState state = graphics.Save();
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x1, y1, MatrixOrder.Append);
graphics.DrawString("S", font, Brushes.White, 0, 0, stringFormat);
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x3, y3, MatrixOrder.Append);
graphics.DrawString("I", font, Brushes.White, 0, 0, stringFormat);
graphics.Restore(state);
}
}
}
return bitmap;
}
#endregion
#region 크기 32 비트맵 구하기 - GetSize32Bitmap()
/// <summary>
/// 크기 32 비트맵 구하기
/// </summary>
/// <returns>크기 32 비트맵</returns>
private Bitmap GetSize32Bitmap()
{
const int width = 32;
const int height = 32;
Bitmap bitmap = new Bitmap(width, height);
using(Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
graphics.Clear(Color.Transparent);
const int thickness = 3;
RectangleF rectangle = new RectangleF
(
thickness / 2f,
thickness / 2f,
width - thickness,
height - thickness
);
using
(
Brush brush = new LinearGradientBrush
(
new PointF(0, 0),
new PointF(0, height),
Color.LightBlue,
Color.Blue
)
)
{
using
(
Brush penBrush = new LinearGradientBrush
(
new PointF(0, 0),
new PointF(0, height),
Color.Blue,
Color.LightBlue
)
)
{
using(Pen pen = new Pen(penBrush, thickness))
{
const float radius = 2 * thickness;
graphics.DrawRoundedRectangle(rectangle, brush, pen, radius);
}
}
}
using(StringFormat stringFormat = new StringFormat())
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
const float fontSize = 10;
using(Font font1 = new Font("Times New Roman", fontSize, FontStyle.Bold))
{
float x1 = width / 3f;
float x2 = width / 2f;
float x3 = width / 3f * 2;
float y1 = height / 3f;
float y2 = height / 2f;
float y3 = height / 3f * 2;
const float fontScale = 1f;
GraphicsState state = graphics.Save();
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x1, y1, MatrixOrder.Append);
graphics.DrawString("S", font1, Brushes.White, 0, 0, stringFormat);
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x3, y3, MatrixOrder.Append);
graphics.DrawString("I", font1, Brushes.White, 0, 0, stringFormat);
using(Font font2 = new Font("Times New Roman", fontSize * 1.2f, FontStyle.Bold))
{
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x2, y2, MatrixOrder.Append);
graphics.DrawString("/", font2, Brushes.White, 0, 0, stringFormat);
}
graphics.Restore(state);
}
}
}
return bitmap;
}
#endregion
#region 크기 48 비트맵 구하기 - GetSize48Bitmap()
/// <summary>
/// 크기 48 비트맵 구하기
/// </summary>
/// <returns>크기 48 비트맵</returns>
private Bitmap GetSize48Bitmap()
{
const int width = 48;
const int height = 48;
Bitmap bitmap = new Bitmap(width, height);
using(Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
graphics.Clear(Color.Transparent);
const int thickness = 5;
RectangleF rectangle = new RectangleF
(
thickness / 2f,
thickness / 2f,
width - thickness,
height - thickness
);
using
(
Brush brush = new LinearGradientBrush
(
new PointF(0, 0),
new PointF(0, height),
Color.LightBlue,
Color.Blue)
)
{
using
(
Brush penBrush = new LinearGradientBrush
(
new PointF(0, 0),
new PointF(0, height),
Color.Blue,
Color.LightBlue
)
)
{
using(Pen pen = new Pen(penBrush, thickness))
{
const float radius = 2 * thickness;
graphics.DrawRoundedRectangle(rectangle, brush, pen, radius);
}
}
}
using(StringFormat stringFormat = new StringFormat())
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
const float fontSize = 15;
using(Font font1 = new Font("Times New Roman", fontSize, FontStyle.Bold))
{
float x1 = width / 3f;
float x2 = width / 2f;
float x3 = width / 3f * 2;
float y1 = height / 3f;
float y2 = height / 2f;
float y3 = height / 3f * 2;
const float fontScale = 1f;
GraphicsState state = graphics.Save();
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x1, y1, MatrixOrder.Append);
graphics.DrawString("S", font1, Brushes.White, 0, 0, stringFormat);
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x3, y3, MatrixOrder.Append);
graphics.DrawString("I", font1, Brushes.White, 0, 0, stringFormat);
using(Font font2 = new Font("Times New Roman", fontSize * 1.2f, FontStyle.Bold))
{
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(x2, y2, MatrixOrder.Append);
graphics.DrawString("/", font2, Brushes.White, 0, 0, stringFormat);
}
graphics.Restore(state);
}
}
}
return bitmap;
}
#endregion
#region 크기 256 비트맵 구하기 - GetSize256Bitmap()
/// <summary>
/// 크기 256 비트맵 구하기
/// </summary>
/// <returns>크기 256 비트맵</returns>
private Bitmap GetSize256Bitmap()
{
const int width = 256;
const int height = 256;
Bitmap bitmap = new Bitmap(width, height);
using(Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
graphics.Clear(Color.Transparent);
const int thickness = 10;
RectangleF rectangle = new RectangleF
(
thickness / 2f,
thickness / 2f,
width - thickness,
height - thickness
);
using
(
Brush brush = new LinearGradientBrush
(
new PointF(0, 0),
new PointF(0, height),
Color.LightBlue,
Color.Blue)
)
{
using
(
Brush penBrush = new LinearGradientBrush
(
new PointF(0, 0),
new PointF(0, height),
Color.Blue,
Color.LightBlue
)
)
{
using(Pen pen = new Pen(penBrush, thickness))
{
const float radius = 4 * thickness;
graphics.DrawRoundedRectangle(rectangle, brush, pen, radius);
}
}
}
using(StringFormat stringFormat = new StringFormat())
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
const float fontSize = 50;
using(Font font = new Font("Times New Roman", fontSize, FontStyle.Bold))
{
float centerX = width / 2f;
float y1 = height / 3f;
float y2 = height / 3f * 2;
const float fontScale = 1.75f;
GraphicsState state = graphics.Save();
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(centerX, y1, MatrixOrder.Append);
graphics.DrawString("Sample", font, Brushes.White, 0, 0, stringFormat);
graphics.ResetTransform();
graphics.ScaleTransform(1, fontScale);
graphics.TranslateTransform(centerX, y2, MatrixOrder.Append);
graphics.DrawString("Icon", font, Brushes.White, 0, 0, stringFormat);
graphics.Restore(state);
}
}
}
return bitmap;
}
#endregion
}
}