์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐ŸŽจ C# ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ์™€ System.Drawing์„ ํ™œ์šฉํ•œ ๊ทธ๋ž˜ํ”ฝ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๐ŸŽจ C# ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ์™€ System.Drawing์„ ํ™œ์šฉํ•œ ๊ทธ๋ž˜ํ”ฝ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์™„๋ฒฝ ๊ฐ€์ด๋“œ

์นœ๊ตฌ์ฒ˜๋Ÿผ ์‰ฝ๊ฒŒ ๋ฐฐ์šฐ๋Š” C# ๊ทธ๋ž˜ํ”ฝ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ๋ชจ๋“  ๊ฒƒ

๐Ÿ‘‹ ์•ˆ๋…•! ์˜ค๋Š˜์€ C#์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•ด๋ณผ๊นŒ ํ•ด. ํ˜น์‹œ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ , ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•˜๊ณ , ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•˜๊ณ , ์‹ฌ์ง€์–ด ๊ทธ๋ฆผ์„ ๊ทธ๋ฆฌ๋Š” ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค์–ด๋ณด๊ณ  ์‹ถ์—ˆ๋˜ ์  ์žˆ์–ด? ๊ทธ๋ ‡๋‹ค๋ฉด ์ œ๋Œ€๋กœ ์ฐพ์•„์™”์–ด!

System.Drawing ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋Š” C#์—์„œ ๊ทธ๋ž˜ํ”ฝ ์ž‘์—…์„ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๊ฐ•๋ ฅํ•œ ๋„๊ตฌ์•ผ. GDI+(Graphics Device Interface Plus)๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๊ณ  ์žˆ์–ด์„œ, Windows ํ™˜๊ฒฝ์—์„œ 2D ๊ทธ๋ž˜ํ”ฝ์„ ๋‹ค๋ฃจ๋Š” ๋ฐ ์ตœ์ ํ™”๋˜์–ด ์žˆ์ง€. ๋ฌผ๋ก  ์ตœ๊ทผ์—๋Š” ํฌ๋กœ์Šค ํ”Œ๋žซํผ ํ™˜๊ฒฝ์„ ์œ„ํ•ด ๋‹ค๋ฅธ ๋Œ€์•ˆ๋“ค๋„ ๋‚˜์˜ค๊ณ  ์žˆ์ง€๋งŒ, System.Drawing์€ ์—ฌ์ „ํžˆ ๋งŽ์€ ๊ฐœ๋ฐœ์ž๋“ค์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒ€์ฆ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์•ผ.

๐ŸŽฏ ์ด ๊ธ€์—์„œ๋Š” ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์‹ค์ „ ํ™œ์šฉ๊นŒ์ง€, ์นœ๊ตฌ์—๊ฒŒ ์„ค๋ช…ํ•˜๋“ฏ์ด ์‰ฝ๊ณ  ์žฌ๋ฏธ์žˆ๊ฒŒ ์•Œ๋ ค์ค„๊ฒŒ. ์ฝ”๋“œ ์˜ˆ์ œ๋„ ํ’๋ถ€ํ•˜๊ฒŒ ์ค€๋น„ํ–ˆ์œผ๋‹ˆ๊นŒ, ๋”ฐ๋ผํ•˜๋‹ค ๋ณด๋ฉด ์–ด๋А์ƒˆ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ „๋ฌธ๊ฐ€๊ฐ€ ๋˜์–ด ์žˆ์„ ๊ฑฐ์•ผ!

๐Ÿ“š System.Drawing ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ดํ•ดํ•˜๊ธฐ

๋จผ์ € System.Drawing์ด ๋ญ”์ง€๋ถ€ํ„ฐ ์•Œ์•„๋ณด์ž. ์ด๊ฑด .NET Framework์— ํฌํ•จ๋œ ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋กœ, ๊ทธ๋ž˜ํ”ฝ ๊ด€๋ จ ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ํด๋ž˜์Šค๋“ค์˜ ์ง‘ํ•ฉ์ด์•ผ.

๐Ÿ” ์ฃผ์š” ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์‚ดํŽด๋ณด๋ฉด:

System.Drawing ์ฃผ์š” ํด๋ž˜์Šค๋“ค: Graphics - ์‹ค์ œ๋กœ ๊ทธ๋ฆผ์„ ๊ทธ๋ฆฌ๋Š” ์บ”๋ฒ„์Šค ์—ญํ• ์„ ํ•˜๋Š” ํ•ต์‹ฌ ํด๋ž˜์Šค์•ผ. ์„ , ๋„ํ˜•, ํ…์ŠคํŠธ, ์ด๋ฏธ์ง€ ๋“ฑ์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ์–ด.

Bitmap - ํ”ฝ์…€ ๊ธฐ๋ฐ˜์˜ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค๋ฃจ๋Š” ํด๋ž˜์Šค. ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๊ฑฐ๋‚˜ ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•ด.

Image - Bitmap์˜ ๋ถ€๋ชจ ํด๋ž˜์Šค๋กœ, ๋” ์ถ”์ƒ์ ์ธ ์ด๋ฏธ์ง€ ๊ฐœ๋…์„ ๋‹ค๋ค„.

Pen - ์„ ์„ ๊ทธ๋ฆด ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋„๊ตฌ. ์ƒ‰์ƒ, ๋‘๊ป˜, ์Šคํƒ€์ผ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์–ด.

Brush - ๋„ํ˜•์„ ์ฑ„์šธ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋„๊ตฌ. ๋‹จ์ƒ‰, ๊ทธ๋ผ๋””์–ธํŠธ, ํŒจํ„ด ๋“ฑ ๋‹ค์–‘ํ•œ ์Šคํƒ€์ผ์ด ์žˆ์–ด.

Color - ์ƒ‰์ƒ์„ ํ‘œํ˜„ํ•˜๋Š” ๊ตฌ์กฐ์ฒด. RGB, ARGB ๊ฐ’์œผ๋กœ ์ƒ‰์„ ์ •์˜ํ•ด.

Font - ํ…์ŠคํŠธ๋ฅผ ๊ทธ๋ฆด ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํฐํŠธ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ์–ด.

๐Ÿ’ก ํŒ: System.Drawing์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ํ”„๋กœ์ ํŠธ์— System.Drawing.dll ์ฐธ์กฐ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ด. .NET Framework ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ํฌํ•จ๋˜์–ด ์žˆ์ง€๋งŒ, .NET Core๋‚˜ .NET 5+ ํ™˜๊ฒฝ์—์„œ๋Š” System.Drawing.Common NuGet ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•ด!

System.Drawing Core Namespace Graphics Bitmap Image Color Pen Brush Font Drawing Tools Lines, Shapes Text, Images Filters, Effects

๐Ÿ–ผ๏ธ ์ด๋ฏธ์ง€ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ์™€ ๊ธฐ๋ณธ ์กฐ์ž‘

์ž, ์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด์ž! ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ์ž‘์—…์ธ ์ด๋ฏธ์ง€ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ๋ถ€ํ„ฐ ์‹œ์ž‘ํ• ๊ฒŒ.

๐Ÿ“‚ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์–ด. ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•๋ถ€ํ„ฐ ์‚ดํŽด๋ณด์ž:

using System;
using System.Drawing;
using System.Drawing.Imaging;

// ๋ฐฉ๋ฒ• 1: ํŒŒ์ผ ๊ฒฝ๋กœ๋กœ ์ง์ ‘ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
Bitmap image = new Bitmap(@"C:\Images\sample.jpg");

// ๋ฐฉ๋ฒ• 2: Image.FromFile ์‚ฌ์šฉ (๋” ์•ˆ์ „ํ•œ ๋ฐฉ๋ฒ•)
Image img = Image.FromFile(@"C:\Images\sample.jpg");
Bitmap bitmap = new Bitmap(img);

// ๋ฐฉ๋ฒ• 3: ์ŠคํŠธ๋ฆผ์„ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
using (FileStream fs = new FileStream(@"C:\Images\sample.jpg", FileMode.Open))
{
    Bitmap streamImage = new Bitmap(fs);
    // ์ž‘์—… ์ˆ˜ํ–‰
}

// ์ด๋ฏธ์ง€ ์ •๋ณด ํ™•์ธ
Console.WriteLine($"๋„ˆ๋น„: {image.Width}px");
Console.WriteLine($"๋†’์ด: {image.Height}px");
Console.WriteLine($"ํฌ๋งท: {image.RawFormat}");
Console.WriteLine($"ํ•ด์ƒ๋„: {image.HorizontalResolution} x {image.VerticalResolution} DPI");

// ์‚ฌ์šฉ ํ›„ ๋ฐ˜๋“œ์‹œ ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œ!
image.Dispose();

โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: Bitmap ๊ฐ์ฒด๋Š” ๊ด€๋ฆฌ๋˜์ง€ ์•Š๋Š” ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์‚ฌ์šฉ์ด ๋๋‚˜๋ฉด ๋ฐ˜๋“œ์‹œ Dispose() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ฑฐ๋‚˜ using ๋ฌธ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ด. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด!


๐Ÿ”„ ์ด๋ฏธ์ง€ ํฌ๊ธฐ ์กฐ์ ˆํ•˜๊ธฐ

์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•˜๋Š” ๊ฑด ์ •๋ง ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋Šฅ์ด์•ผ. ์ธ๋„ค์ผ์„ ๋งŒ๋“ค๊ฑฐ๋‚˜, ์›น์— ์ตœ์ ํ™”๋œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ํ•„์ˆ˜์ ์ด์ง€:

public Bitmap ResizeImage(Image image, int width, int height)
{
    // ์ƒˆ๋กœ์šด ํฌ๊ธฐ์˜ Bitmap ์ƒ์„ฑ
    Bitmap resizedImage = new Bitmap(width, height);
    
    // Graphics ๊ฐ์ฒด ์ƒ์„ฑ
    using (Graphics graphics = Graphics.FromImage(resizedImage))
    {
        // ๊ณ ํ’ˆ์งˆ ๋ Œ๋”๋ง ์„ค์ •
        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        
        // ์ด๋ฏธ์ง€ ๊ทธ๋ฆฌ๊ธฐ
        graphics.DrawImage(image, 0, 0, width, height);
    }
    
    return resizedImage;
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
using (Image original = Image.FromFile(@"C:\Images\large.jpg"))
{
    Bitmap thumbnail = ResizeImage(original, 200, 150);
    thumbnail.Save(@"C:\Images\thumbnail.jpg", ImageFormat.Jpeg);
    thumbnail.Dispose();
}

๐Ÿ’ก ํ”„๋กœ ํŒ: InterpolationMode๋ฅผ ์„ค์ •ํ•˜๋ฉด ์ด๋ฏธ์ง€ ํ’ˆ์งˆ์„ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์–ด. HighQualityBicubic์€ ๊ฐ€์žฅ ์ข‹์€ ํ’ˆ์งˆ์„ ์ œ๊ณตํ•˜์ง€๋งŒ ์ฒ˜๋ฆฌ ์†๋„๊ฐ€ ๋А๋ ค. ์†๋„๊ฐ€ ์ค‘์š”ํ•˜๋‹ค๋ฉด Bilinear๋‚˜ Low๋ฅผ ์‚ฌ์šฉํ•ด๋ด!


๐Ÿ“ ๋น„์œจ ์œ ์ง€ํ•˜๋ฉฐ ํฌ๊ธฐ ์กฐ์ ˆํ•˜๊ธฐ

์›๋ณธ ์ด๋ฏธ์ง€์˜ ๊ฐ€๋กœ์„ธ๋กœ ๋น„์œจ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•˜๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•ด. ์ด๋ฏธ์ง€๊ฐ€ ์ฐŒ๊ทธ๋Ÿฌ์ง€๋Š” ๊ฑธ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ :

public Bitmap ResizeImageKeepAspectRatio(Image image, int maxWidth, int maxHeight)
{
    // ์›๋ณธ ๋น„์œจ ๊ณ„์‚ฐ
    double ratioX = (double)maxWidth / image.Width;
    double ratioY = (double)maxHeight / image.Height;
    double ratio = Math.Min(ratioX, ratioY);
    
    // ์ƒˆ๋กœ์šด ํฌ๊ธฐ ๊ณ„์‚ฐ
    int newWidth = (int)(image.Width * ratio);
    int newHeight = (int)(image.Height * ratio);
    
    // ํฌ๊ธฐ ์กฐ์ ˆ
    Bitmap resizedImage = new Bitmap(newWidth, newHeight);
    
    using (Graphics graphics = Graphics.FromImage(resizedImage))
    {
        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        graphics.DrawImage(image, 0, 0, newWidth, newHeight);
    }
    
    return resizedImage;
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
using (Image original = Image.FromFile(@"C:\Images\photo.jpg"))
{
    // ์ตœ๋Œ€ 800x600 ํฌ๊ธฐ๋กœ ์กฐ์ ˆ (๋น„์œจ ์œ ์ง€)
    Bitmap resized = ResizeImageKeepAspectRatio(original, 800, 600);
    resized.Save(@"C:\Images\resized.jpg", ImageFormat.Jpeg);
    resized.Dispose();
}

๐ŸŽจ Graphics ํด๋ž˜์Šค๋กœ ๊ทธ๋ฆผ ๊ทธ๋ฆฌ๊ธฐ

์ด์ œ ์ง„์งœ ์žฌ๋ฏธ์žˆ๋Š” ๋ถ€๋ถ„์ด์•ผ! Graphics ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ”„๋กœ๊ทธ๋ž˜๋ฐ์œผ๋กœ ๊ทธ๋ฆผ์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ์–ด. ๋งˆ์น˜ ๋””์ง€ํ„ธ ์บ”๋ฒ„์Šค์— ๋ถ“์œผ๋กœ ๊ทธ๋ฆผ์„ ๊ทธ๋ฆฌ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ง์ด์•ผ.

โœ๏ธ ์„ ๊ณผ ๋„ํ˜• ๊ทธ๋ฆฌ๊ธฐ

// ์ƒˆ๋กœ์šด Bitmap ์ƒ์„ฑ (800x600 ํฌ๊ธฐ)
Bitmap canvas = new Bitmap(800, 600);

using (Graphics g = Graphics.FromImage(canvas))
{
    // ๋ฐฐ๊ฒฝ์„ ํฐ์ƒ‰์œผ๋กœ ์ฑ„์šฐ๊ธฐ
    g.Clear(Color.White);
    
    // ์•ˆํ‹ฐ์•จ๋ฆฌ์–ด์‹ฑ ํ™œ์„ฑํ™” (๋ถ€๋“œ๋Ÿฌ์šด ์„ )
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    
    // ๋นจ๊ฐ„์ƒ‰ ํŽœ ์ƒ์„ฑ (๋‘๊ป˜ 3px)
    using (Pen redPen = new Pen(Color.Red, 3))
    {
        // ์„  ๊ทธ๋ฆฌ๊ธฐ
        g.DrawLine(redPen, 50, 50, 200, 200);
        
        // ์‚ฌ๊ฐํ˜• ๊ทธ๋ฆฌ๊ธฐ (ํ…Œ๋‘๋ฆฌ๋งŒ)
        g.DrawRectangle(redPen, 250, 50, 150, 100);
        
        // ์› ๊ทธ๋ฆฌ๊ธฐ
        g.DrawEllipse(redPen, 450, 50, 100, 100);
    }
    
    // ํŒŒ๋ž€์ƒ‰ ๋ธŒ๋Ÿฌ์‹œ๋กœ ์ฑ„์›Œ์ง„ ๋„ํ˜• ๊ทธ๋ฆฌ๊ธฐ
    using (SolidBrush blueBrush = new SolidBrush(Color.Blue))
    {
        // ์ฑ„์›Œ์ง„ ์‚ฌ๊ฐํ˜•
        g.FillRectangle(blueBrush, 50, 250, 150, 100);
        
        // ์ฑ„์›Œ์ง„ ์›
        g.FillEllipse(blueBrush, 250, 250, 100, 100);
    }
    
    // ๊ทธ๋ผ๋””์–ธํŠธ ๋ธŒ๋Ÿฌ์‹œ ์‚ฌ์šฉ
    using (System.Drawing.Drawing2D.LinearGradientBrush gradBrush = 
           new System.Drawing.Drawing2D.LinearGradientBrush(
               new Rectangle(400, 250, 200, 150),
               Color.Yellow,
               Color.Orange,
               45f))
    {
        g.FillRectangle(gradBrush, 400, 250, 200, 150);
    }
}

// ์ €์žฅ
canvas.Save(@"C:\Images\drawing.png", ImageFormat.Png);
canvas.Dispose();

์ฃผ์š” ๊ทธ๋ฆฌ๊ธฐ ๋ฉ”์„œ๋“œ๋“ค: DrawLine() - ์„  ๊ทธ๋ฆฌ๊ธฐ
DrawRectangle() - ์‚ฌ๊ฐํ˜• ํ…Œ๋‘๋ฆฌ ๊ทธ๋ฆฌ๊ธฐ
FillRectangle() - ์ฑ„์›Œ์ง„ ์‚ฌ๊ฐํ˜• ๊ทธ๋ฆฌ๊ธฐ
DrawEllipse() - ์›/ํƒ€์› ํ…Œ๋‘๋ฆฌ ๊ทธ๋ฆฌ๊ธฐ
FillEllipse() - ์ฑ„์›Œ์ง„ ์›/ํƒ€์› ๊ทธ๋ฆฌ๊ธฐ
DrawPolygon() - ๋‹ค๊ฐํ˜• ํ…Œ๋‘๋ฆฌ ๊ทธ๋ฆฌ๊ธฐ
FillPolygon() - ์ฑ„์›Œ์ง„ ๋‹ค๊ฐํ˜• ๊ทธ๋ฆฌ๊ธฐ
DrawArc() - ํ˜ธ ๊ทธ๋ฆฌ๊ธฐ
DrawBezier() - ๋ฒ ์ง€์–ด ๊ณก์„  ๊ทธ๋ฆฌ๊ธฐ
DrawCurve() - ๋ถ€๋“œ๋Ÿฌ์šด ๊ณก์„  ๊ทธ๋ฆฌ๊ธฐ


๐Ÿ“ ํ…์ŠคํŠธ ๊ทธ๋ฆฌ๊ธฐ

์ด๋ฏธ์ง€์— ํ…์ŠคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ๋„ ์ •๋ง ์œ ์šฉํ•ด. ์›Œํ„ฐ๋งˆํฌ๋ฅผ ๋„ฃ๊ฑฐ๋‚˜, ์„ค๋ช…์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜, ์ฐจํŠธ๋ฅผ ๋งŒ๋“ค ๋•Œ ํ•„์ˆ˜์ ์ด์ง€:

using (Graphics g = Graphics.FromImage(canvas))
{
    // ํ…์ŠคํŠธ ๋ Œ๋”๋ง ํ’ˆ์งˆ ์„ค์ •
    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
    
    // ํฐํŠธ ์ƒ์„ฑ
    using (Font titleFont = new Font("๋ง‘์€ ๊ณ ๋”•", 32, FontStyle.Bold))
    using (Font normalFont = new Font("๋ง‘์€ ๊ณ ๋”•", 16, FontStyle.Regular))
    using (SolidBrush blackBrush = new SolidBrush(Color.Black))
    using (SolidBrush whiteBrush = new SolidBrush(Color.White))
    {
        // ์ œ๋ชฉ ๊ทธ๋ฆฌ๊ธฐ
        g.DrawString("C# ๊ทธ๋ž˜ํ”ฝ ํ”„๋กœ๊ทธ๋ž˜๋ฐ", titleFont, blackBrush, 50, 50);
        
        // ์ผ๋ฐ˜ ํ…์ŠคํŠธ
        g.DrawString("System.Drawing์„ ํ™œ์šฉํ•œ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ", 
                     normalFont, blackBrush, 50, 100);
        
        // ํ…์ŠคํŠธ ํฌ๊ธฐ ์ธก์ •
        SizeF textSize = g.MeasureString("์ธก์ •ํ•  ํ…์ŠคํŠธ", normalFont);
        Console.WriteLine($"ํ…์ŠคํŠธ ํฌ๊ธฐ: {textSize.Width} x {textSize.Height}");
        
        // ์ค‘์•™ ์ •๋ ฌ ํ…์ŠคํŠธ
        string centerText = "์ค‘์•™ ์ •๋ ฌ";
        SizeF size = g.MeasureString(centerText, normalFont);
        float x = (canvas.Width - size.Width) / 2;
        float y = (canvas.Height - size.Height) / 2;
        g.DrawString(centerText, normalFont, blackBrush, x, y);
        
        // ํšŒ์ „๋œ ํ…์ŠคํŠธ
        g.TranslateTransform(400, 300);
        g.RotateTransform(45);
        g.DrawString("ํšŒ์ „๋œ ํ…์ŠคํŠธ", normalFont, blackBrush, 0, 0);
        g.ResetTransform();
    }
}

โœจ ์‹ค์ „ ํ™œ์šฉ: ์žฌ๋Šฅ๋„ท(https://www.jaenung.net)์—์„œ ๋””์ž์ธ ์žฌ๋Šฅ์„ ๊ฑฐ๋ž˜ํ•˜๋Š” ๋ถ„๋“ค์ด ์ž๋™์œผ๋กœ ์›Œํ„ฐ๋งˆํฌ๋ฅผ ๋„ฃ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค ๋•Œ ์ด๋Ÿฐ ํ…์ŠคํŠธ ๊ทธ๋ฆฌ๊ธฐ ๊ธฐ๋Šฅ์„ ๋งŽ์ด ํ™œ์šฉํ•ด. ํฌํŠธํด๋ฆฌ์˜ค ์ด๋ฏธ์ง€์— ์ž๋™์œผ๋กœ ๋กœ๊ณ ๋‚˜ ์ €์ž‘๊ถŒ ํ‘œ์‹œ๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ๊ฑฐ๋“ !

๐ŸŽญ ์ด๋ฏธ์ง€ ํ•„ํ„ฐ์™€ ํšจ๊ณผ ์ ์šฉํ•˜๊ธฐ

์ด์ œ ์ข€ ๋” ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ์œผ๋กœ ๋„˜์–ด๊ฐ€๋ณผ๊นŒ? ์ด๋ฏธ์ง€์— ๋‹ค์–‘ํ•œ ํ•„ํ„ฐ์™€ ํšจ๊ณผ๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž.

๐ŸŒˆ ์ƒ‰์ƒ ์กฐ์ž‘ํ•˜๊ธฐ

ํ”ฝ์…€ ๋‹จ์œ„๋กœ ์ƒ‰์ƒ์„ ์กฐ์ž‘ํ•˜๋ฉด ์ •๋ง ๋‹ค์–‘ํ•œ ํšจ๊ณผ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด:

// ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ ๋ณ€ํ™˜
public Bitmap ConvertToGrayscale(Bitmap original)
{
    Bitmap grayscale = new Bitmap(original.Width, original.Height);
    
    for (int y = 0; y < original.Height; y++)
    {
        for (int x = 0; x < original.Width; x++)
        {
            Color originalColor = original.GetPixel(x, y);
            
            // ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ ๊ณต์‹ (์ธ๊ฐ„์˜ ๋ˆˆ์ด ์ƒ‰์„ ์ธ์‹ํ•˜๋Š” ๋น„์œจ ๋ฐ˜์˜)
            int grayValue = (int)(originalColor.R * 0.299 + 
                                  originalColor.G * 0.587 + 
                                  originalColor.B * 0.114);
            
            Color grayColor = Color.FromArgb(originalColor.A, 
                                             grayValue, 
                                             grayValue, 
                                             grayValue);
            
            grayscale.SetPixel(x, y, grayColor);
        }
    }
    
    return grayscale;
}

// ๋ฐ๊ธฐ ์กฐ์ ˆ
public Bitmap AdjustBrightness(Bitmap original, int brightness)
{
    Bitmap adjusted = new Bitmap(original.Width, original.Height);
    
    for (int y = 0; y < original.Height; y++)
    {
        for (int x = 0; x < original.Width; x++)
        {
            Color originalColor = original.GetPixel(x, y);
            
            int r = Math.Min(255, Math.Max(0, originalColor.R + brightness));
            int g = Math.Min(255, Math.Max(0, originalColor.G + brightness));
            int b = Math.Min(255, Math.Max(0, originalColor.B + brightness));
            
            adjusted.SetPixel(x, y, Color.FromArgb(originalColor.A, r, g, b));
        }
    }
    
    return adjusted;
}

// ๋Œ€๋น„ ์กฐ์ ˆ
public Bitmap AdjustContrast(Bitmap original, double contrast)
{
    Bitmap adjusted = new Bitmap(original.Width, original.Height);
    double factor = (259.0 * (contrast + 255.0)) / (255.0 * (259.0 - contrast));
    
    for (int y = 0; y < original.Height; y++)
    {
        for (int x = 0; x < original.Width; x++)
        {
            Color originalColor = original.GetPixel(x, y);
            
            int r = (int)Math.Min(255, Math.Max(0, factor * (originalColor.R - 128) + 128));
            int g = (int)Math.Min(255, Math.Max(0, factor * (originalColor.G - 128) + 128));
            int b = (int)Math.Min(255, Math.Max(0, factor * (originalColor.B - 128) + 128));
            
            adjusted.SetPixel(x, y, Color.FromArgb(originalColor.A, r, g, b));
        }
    }
    
    return adjusted;
}

โš ๏ธ ์„ฑ๋Šฅ ์ฃผ์˜: GetPixel()๊ณผ SetPixel()์€ ํŽธ๋ฆฌํ•˜์ง€๋งŒ ๋งค์šฐ ๋А๋ ค. ํฐ ์ด๋ฏธ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ๋Š” LockBits()๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ง์ ‘ ๋ฉ”๋ชจ๋ฆฌ์— ์ ‘๊ทผํ•˜๋Š” ๊ฒŒ ํ›จ์”ฌ ๋นจ๋ผ. ์•„๋ž˜์—์„œ ์ž์„ธํžˆ ์„ค๋ช…ํ• ๊ฒŒ!


โšก ๊ณ ์† ํ”ฝ์…€ ์ฒ˜๋ฆฌ (LockBits ์‚ฌ์šฉ)

๋Œ€์šฉ๋Ÿ‰ ์ด๋ฏธ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ๋Š” ์„ฑ๋Šฅ์ด ์ •๋ง ์ค‘์š”ํ•ด. LockBits๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด GetPixel/SetPixel๋ณด๋‹ค ์ˆ˜์‹ญ ๋ฐฐ ๋น ๋ฅด๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด:

public unsafe Bitmap FastGrayscale(Bitmap original)
{
    Bitmap grayscale = new Bitmap(original.Width, original.Height);
    
    // ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ ์ž ๊ธˆ
    Rectangle rect = new Rectangle(0, 0, original.Width, original.Height);
    BitmapData originalData = original.LockBits(rect, ImageLockMode.ReadOnly, 
                                                 PixelFormat.Format24bppRgb);
    BitmapData grayscaleData = grayscale.LockBits(rect, ImageLockMode.WriteOnly, 
                                                   PixelFormat.Format24bppRgb);
    
    int bytes = Math.Abs(originalData.Stride) * original.Height;
    byte[] rgbValues = new byte[bytes];
    byte[] grayValues = new byte[bytes];
    
    // ์›๋ณธ ๋ฐ์ดํ„ฐ ๋ณต์‚ฌ
    System.Runtime.InteropServices.Marshal.Copy(originalData.Scan0, rgbValues, 0, bytes);
    
    // ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ ๋ณ€ํ™˜
    for (int i = 0; i < bytes; i += 3)
    {
        byte gray = (byte)(rgbValues[i] * 0.114 +      // Blue
                          rgbValues[i + 1] * 0.587 +   // Green
                          rgbValues[i + 2] * 0.299);   // Red
        
        grayValues[i] = gray;
        grayValues[i + 1] = gray;
        grayValues[i + 2] = gray;
    }
    
    // ๋ณ€ํ™˜๋œ ๋ฐ์ดํ„ฐ ๋ณต์‚ฌ
    System.Runtime.InteropServices.Marshal.Copy(grayValues, 0, grayscaleData.Scan0, bytes);
    
    // ์ž ๊ธˆ ํ•ด์ œ
    original.UnlockBits(originalData);
    grayscale.UnlockBits(grayscaleData);
    
    return grayscale;
}

๐Ÿ’ก ์„ฑ๋Šฅ ๋น„๊ต: 1920x1080 ์ด๋ฏธ์ง€๋ฅผ ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ, GetPixel/SetPixel์€ ์•ฝ 2~3์ดˆ๊ฐ€ ๊ฑธ๋ฆฌ์ง€๋งŒ, LockBits๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด 0.1์ดˆ ์ด๋‚ด๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด. ์•ฝ 20~30๋ฐฐ ๋น ๋ฅธ ๊ฑฐ์ง€!


๐ŸŽจ ColorMatrix๋ฅผ ์‚ฌ์šฉํ•œ ์ƒ‰์ƒ ๋ณ€ํ™˜

ColorMatrix๋Š” ๋” ๊ฐ„ํŽธํ•˜๊ณ  ๊ฐ•๋ ฅํ•œ ์ƒ‰์ƒ ๋ณ€ํ™˜ ๋ฐฉ๋ฒ•์ด์•ผ. ํ–‰๋ ฌ ์—ฐ์‚ฐ์„ ํ†ตํ•ด ๋‹ค์–‘ํ•œ ํšจ๊ณผ๋ฅผ ์‰ฝ๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ์–ด:

public Bitmap ApplyColorMatrix(Bitmap original, ColorMatrix colorMatrix)
{
    Bitmap result = new Bitmap(original.Width, original.Height);
    
    using (Graphics g = Graphics.FromImage(result))
    {
        // ImageAttributes ์ƒ์„ฑ ๋ฐ ColorMatrix ์„ค์ •
        ImageAttributes attributes = new ImageAttributes();
        attributes.SetColorMatrix(colorMatrix);
        
        // ์ด๋ฏธ์ง€ ๊ทธ๋ฆฌ๊ธฐ
        g.DrawImage(original,
                   new Rectangle(0, 0, original.Width, original.Height),
                   0, 0, original.Width, original.Height,
                   GraphicsUnit.Pixel,
                   attributes);
    }
    
    return result;
}

// ์„ธํ”ผ์•„ ํšจ๊ณผ
public Bitmap ApplySepiaEffect(Bitmap original)
{
    ColorMatrix sepiaMatrix = new ColorMatrix(new float[][]
    {
        new float[] {0.393f, 0.349f, 0.272f, 0, 0},
        new float[] {0.769f, 0.686f, 0.534f, 0, 0},
        new float[] {0.189f, 0.168f, 0.131f, 0, 0},
        new float[] {0, 0, 0, 1, 0},
        new float[] {0, 0, 0, 0, 1}
    });
    
    return ApplyColorMatrix(original, sepiaMatrix);
}

// ๋„ค๊ฑฐํ‹ฐ๋ธŒ ํšจ๊ณผ
public Bitmap ApplyNegativeEffect(Bitmap original)
{
    ColorMatrix negativeMatrix = new ColorMatrix(new float[][]
    {
        new float[] {-1, 0, 0, 0, 0},
        new float[] {0, -1, 0, 0, 0},
        new float[] {0, 0, -1, 0, 0},
        new float[] {0, 0, 0, 1, 0},
        new float[] {1, 1, 1, 0, 1}
    });
    
    return ApplyColorMatrix(original, negativeMatrix);
}

// ํˆฌ๋ช…๋„ ์กฐ์ ˆ
public Bitmap AdjustOpacity(Bitmap original, float opacity)
{
    ColorMatrix opacityMatrix = new ColorMatrix(new float[][]
    {
        new float[] {1, 0, 0, 0, 0},
        new float[] {0, 1, 0, 0, 0},
        new float[] {0, 0, 1, 0, 0},
        new float[] {0, 0, 0, opacity, 0},
        new float[] {0, 0, 0, 0, 1}
    });
    
    return ApplyColorMatrix(original, opacityMatrix);
}
Image Processing Pipeline Original Image Load Color Adjustment Brightness Contrast Process Filters Effects Grayscale Sepia Apply Result Image Performance Tips Use LockBits for large images ColorMatrix for color operations 20-30x faster! Memory Management Always Dispose Bitmap objects Use using statement Prevent memory leaks

๐Ÿ–Œ๏ธ ๊ณ ๊ธ‰ ๊ทธ๋ž˜ํ”ฝ ๊ธฐ๋ฒ•

์ด์ œ ์ข€ ๋” ์ „๋ฌธ์ ์ธ ๊ธฐ๋ฒ•๋“ค์„ ๋ฐฐ์›Œ๋ณด์ž. ์ด๋Ÿฐ ๊ธฐ์ˆ ๋“ค์„ ์ตํžˆ๋ฉด ์ •๋ง ๋ฉ‹์ง„ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด!

๐Ÿ”„ ์ด๋ฏธ์ง€ ํšŒ์ „๊ณผ ๋ณ€ํ™˜

// ์ด๋ฏธ์ง€ ํšŒ์ „
public Bitmap RotateImage(Bitmap original, float angle)
{
    // ํšŒ์ „ ํ›„ ์ด๋ฏธ์ง€๊ฐ€ ์ž˜๋ฆฌ์ง€ ์•Š๋„๋ก ์ƒˆ๋กœ์šด ํฌ๊ธฐ ๊ณ„์‚ฐ
    double radians = angle * Math.PI / 180;
    double cos = Math.Abs(Math.Cos(radians));
    double sin = Math.Abs(Math.Sin(radians));
    
    int newWidth = (int)(original.Width * cos + original.Height * sin);
    int newHeight = (int)(original.Width * sin + original.Height * cos);
    
    Bitmap rotated = new Bitmap(newWidth, newHeight);
    
    using (Graphics g = Graphics.FromImage(rotated))
    {
        g.Clear(Color.Transparent);
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        
        // ์ค‘์‹ฌ์ ์œผ๋กœ ์ด๋™
        g.TranslateTransform(newWidth / 2f, newHeight / 2f);
        
        // ํšŒ์ „
        g.RotateTransform(angle);
        
        // ์›๋ณธ ์ด๋ฏธ์ง€ ์ค‘์‹ฌ์œผ๋กœ ์ด๋™
        g.TranslateTransform(-original.Width / 2f, -original.Height / 2f);
        
        // ์ด๋ฏธ์ง€ ๊ทธ๋ฆฌ๊ธฐ
        g.DrawImage(original, new Point(0, 0));
    }
    
    return rotated;
}

// ์ด๋ฏธ์ง€ ๋’ค์ง‘๊ธฐ
public Bitmap FlipImage(Bitmap original, bool horizontal, bool vertical)
{
    Bitmap flipped = (Bitmap)original.Clone();
    
    if (horizontal && vertical)
        flipped.RotateFlip(RotateFlipType.RotateNoneFlipXY);
    else if (horizontal)
        flipped.RotateFlip(RotateFlipType.RotateNoneFlipX);
    else if (vertical)
        flipped.RotateFlip(RotateFlipType.RotateNoneFlipY);
    
    return flipped;
}

// ์ด๋ฏธ์ง€ ์ž๋ฅด๊ธฐ
public Bitmap CropImage(Bitmap original, Rectangle cropArea)
{
    Bitmap cropped = new Bitmap(cropArea.Width, cropArea.Height);
    
    using (Graphics g = Graphics.FromImage(cropped))
    {
        g.DrawImage(original,
                   new Rectangle(0, 0, cropArea.Width, cropArea.Height),
                   cropArea,
                   GraphicsUnit.Pixel);
    }
    
    return cropped;
}


๐ŸŽญ ๋ธ”๋Ÿฌ(ํ๋ฆผ) ํšจ๊ณผ

๋ธ”๋Ÿฌ ํšจ๊ณผ๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๋งŒ๋“ค๊ฑฐ๋‚˜ ๋ฐฐ๊ฒฝ์„ ํ๋ฆฌ๊ฒŒ ํ•  ๋•Œ ์‚ฌ์šฉํ•ด. ๊ฐ€์šฐ์‹œ์•ˆ ๋ธ”๋Ÿฌ๊ฐ€ ๊ฐ€์žฅ ์ž์—ฐ์Šค๋Ÿฌ์šด ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค์–ด:

// ๊ฐ„๋‹จํ•œ ๋ฐ•์Šค ๋ธ”๋Ÿฌ
public Bitmap ApplyBoxBlur(Bitmap original, int radius)
{
    Bitmap blurred = new Bitmap(original.Width, original.Height);
    
    for (int y = 0; y < original.Height; y++)
    {
        for (int x = 0; x < original.Width; x++)
        {
            int r = 0, g = 0, b = 0;
            int count = 0;
            
            // ์ฃผ๋ณ€ ํ”ฝ์…€์˜ ํ‰๊ท  ๊ณ„์‚ฐ
            for (int dy = -radius; dy <= radius; dy++)
            {
                for (int dx = -radius; dx <= radius; dx++)
                {
                    int nx = x + dx;
                    int ny = y + dy;
                    
                    if (nx >= 0 && nx < original.Width && 
                        ny >= 0 && ny < original.Height)
                    {
                        Color pixel = original.GetPixel(nx, ny);
                        r += pixel.R;
                        g += pixel.G;
                        b += pixel.B;
                        count++;
                    }
                }
            }
            
            Color avgColor = Color.FromArgb(r / count, g / count, b / count);
            blurred.SetPixel(x, y, avgColor);
        }
    }
    
    return blurred;
}

// ๊ฐ€์šฐ์‹œ์•ˆ ๋ธ”๋Ÿฌ (๋” ์ž์—ฐ์Šค๋Ÿฌ์šด ๊ฒฐ๊ณผ)
public Bitmap ApplyGaussianBlur(Bitmap original, double sigma)
{
    int radius = (int)Math.Ceiling(sigma * 3);
    int size = radius * 2 + 1;
    
    // ๊ฐ€์šฐ์‹œ์•ˆ ์ปค๋„ ์ƒ์„ฑ
    double[,] kernel = new double[size, size];
    double sum = 0;
    
    for (int y = -radius; y <= radius; y++)
    {
        for (int x = -radius; x <= radius; x++)
        {
            double value = Math.Exp(-(x * x + y * y) / (2 * sigma * sigma));
            kernel[y + radius, x + radius] = value;
            sum += value;
        }
    }
    
    // ์ •๊ทœํ™”
    for (int y = 0; y < size; y++)
        for (int x = 0; x < size; x++)
            kernel[y, x] /= sum;
    
    // ๋ธ”๋Ÿฌ ์ ์šฉ
    Bitmap blurred = new Bitmap(original.Width, original.Height);
    
    for (int y = 0; y < original.Height; y++)
    {
        for (int x = 0; x < original.Width; x++)
        {
            double r = 0, g = 0, b = 0;
            
            for (int ky = 0; ky < size; ky++)
            {
                for (int kx = 0; kx < size; kx++)
                {
                    int px = x + kx - radius;
                    int py = y + ky - radius;
                    
                    if (px >= 0 && px < original.Width && 
                        py >= 0 && py < original.Height)
                    {
                        Color pixel = original.GetPixel(px, py);
                        double weight = kernel[ky, kx];
                        
                        r += pixel.R * weight;
                        g += pixel.G * weight;
                        b += pixel.B * weight;
                    }
                }
            }
            
            Color blurredColor = Color.FromArgb(
                Math.Min(255, Math.Max(0, (int)r)),
                Math.Min(255, Math.Max(0, (int)g)),
                Math.Min(255, Math.Max(0, (int)b))
            );
            
            blurred.SetPixel(x, y, blurredColor);
        }
    }
    
    return blurred;
}

๐Ÿ’ก ์ตœ์ ํ™” ํŒ: ์œ„ ์ฝ”๋“œ๋Š” ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๊ฒŒ ์ž‘์„ฑํ–ˆ์ง€๋งŒ, ์‹ค์ œ ํ”„๋กœ๋•์…˜์—์„œ๋Š” LockBits๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์ˆ˜ํ‰/์ˆ˜์ง ๋ถ„๋ฆฌ ๋ธ”๋Ÿฌ๋ฅผ ์ ์šฉํ•˜๋ฉด ํ›จ์”ฌ ๋น ๋ฅด๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด. ๊ฐ€์šฐ์‹œ์•ˆ ๋ธ”๋Ÿฌ๋Š” ๋ถ„๋ฆฌ ๊ฐ€๋Šฅํ•œ ํ•„ํ„ฐ๋ผ์„œ 2D ์—ฐ์‚ฐ์„ 1D ์—ฐ์‚ฐ ๋‘ ๋ฒˆ์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๊ฑฐ๋“ !


๐Ÿ” ์ƒคํ”„๋‹(์„ ๋ช…๋„ ํ–ฅ์ƒ)

// ์–ธ์ƒคํ”„ ๋งˆ์Šคํฌ (Unsharp Mask)
public Bitmap ApplySharpen(Bitmap original, float amount)
{
    // ๋ธ”๋Ÿฌ๋œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
    Bitmap blurred = ApplyBoxBlur(original, 1);
    
    Bitmap sharpened = new Bitmap(original.Width, original.Height);
    
    for (int y = 0; y < original.Height; y++)
    {
        for (int x = 0; x < original.Width; x++)
        {
            Color origColor = original.GetPixel(x, y);
            Color blurColor = blurred.GetPixel(x, y);
            
            // ์›๋ณธ - ๋ธ”๋Ÿฌ = ๋””ํ…Œ์ผ
            // ์›๋ณธ + (๋””ํ…Œ์ผ * amount) = ์ƒคํ”„๋‹
            int r = Math.Min(255, Math.Max(0, 
                (int)(origColor.R + (origColor.R - blurColor.R) * amount)));
            int g = Math.Min(255, Math.Max(0, 
                (int)(origColor.G + (origColor.G - blurColor.G) * amount)));
            int b = Math.Min(255, Math.Max(0, 
                (int)(origColor.B + (origColor.B - blurColor.B) * amount)));
            
            sharpened.SetPixel(x, y, Color.FromArgb(r, g, b));
        }
    }
    
    blurred.Dispose();
    return sharpened;
}

// ์ปจ๋ณผ๋ฃจ์…˜ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•œ ์ƒคํ”„๋‹
public Bitmap ApplyConvolutionSharpen(Bitmap original)
{
    // ์ƒคํ”„๋‹ ์ปค๋„
    double[,] kernel = new double[,]
    {
        { 0, -1,  0 },
        {-1,  5, -1 },
        { 0, -1,  0 }
    };
    
    return ApplyConvolution(original, kernel);
}

// ๋ฒ”์šฉ ์ปจ๋ณผ๋ฃจ์…˜ ํ•„ํ„ฐ
public Bitmap ApplyConvolution(Bitmap original, double[,] kernel)
{
    int kernelSize = kernel.GetLength(0);
    int radius = kernelSize / 2;
    
    Bitmap result = new Bitmap(original.Width, original.Height);
    
    for (int y = radius; y < original.Height - radius; y++)
    {
        for (int x = radius; x < original.Width - radius; x++)
        {
            double r = 0, g = 0, b = 0;
            
            for (int ky = 0; ky < kernelSize; ky++)
            {
                for (int kx = 0; kx < kernelSize; kx++)
                {
                    Color pixel = original.GetPixel(
                        x + kx - radius, 
                        y + ky - radius
                    );
                    
                    double weight = kernel[ky, kx];
                    r += pixel.R * weight;
                    g += pixel.G * weight;
                    b += pixel.B * weight;
                }
            }
            
            Color newColor = Color.FromArgb(
                Math.Min(255, Math.Max(0, (int)r)),
                Math.Min(255, Math.Max(0, (int)g)),
                Math.Min(255, Math.Max(0, (int)b))
            );
            
            result.SetPixel(x, y, newColor);
        }
    }
    
    return result;
}

๐ŸŽฌ ์‹ค์ „ ํ”„๋กœ์ ํŠธ: ์ด๋ฏธ์ง€ ํŽธ์ง‘๊ธฐ ๋งŒ๋“ค๊ธฐ

์ด์ œ ๋ฐฐ์šด ๋‚ด์šฉ์„ ์ข…ํ•ฉํ•ด์„œ ์‹ค์ œ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ์ด๋ฏธ์ง€ ํŽธ์ง‘๊ธฐ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž!

๐Ÿ› ๏ธ ImageProcessor ํด๋ž˜์Šค ์„ค๊ณ„

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

public class ImageProcessor
{
    private Bitmap currentImage;
    private Stack<Bitmap> undoStack;
    private Stack<Bitmap> redoStack;
    
    public ImageProcessor()
    {
        undoStack = new Stack<Bitmap>();
        redoStack = new Stack<Bitmap>();
    }
    
    // ์ด๋ฏธ์ง€ ๋กœ๋“œ
    public void LoadImage(string filePath)
    {
        if (currentImage != null)
            currentImage.Dispose();
        
        currentImage = new Bitmap(filePath);
        undoStack.Clear();
        redoStack.Clear();
    }
    
    // ํ˜„์žฌ ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
    public Bitmap GetCurrentImage()
    {
        return (Bitmap)currentImage.Clone();
    }
    
    // ์ž‘์—… ์ „ ์ƒํƒœ ์ €์žฅ
    private void SaveState()
    {
        undoStack.Push((Bitmap)currentImage.Clone());
        redoStack.Clear();
    }
    
    // ์‹คํ–‰ ์ทจ์†Œ
    public void Undo()
    {
        if (undoStack.Count > 0)
        {
            redoStack.Push(currentImage);
            currentImage = undoStack.Pop();
        }
    }
    
    // ๋‹ค์‹œ ์‹คํ–‰
    public void Redo()
    {
        if (redoStack.Count > 0)
        {
            undoStack.Push(currentImage);
            currentImage = redoStack.Pop();
        }
    }
    
    // ํฌ๊ธฐ ์กฐ์ ˆ
    public void Resize(int width, int height, bool keepAspectRatio = true)
    {
        SaveState();
        
        if (keepAspectRatio)
        {
            double ratioX = (double)width / currentImage.Width;
            double ratioY = (double)height / currentImage.Height;
            double ratio = Math.Min(ratioX, ratioY);
            
            width = (int)(currentImage.Width * ratio);
            height = (int)(currentImage.Height * ratio);
        }
        
        Bitmap resized = new Bitmap(width, height);
        using (Graphics g = Graphics.FromImage(resized))
        {
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.DrawImage(currentImage, 0, 0, width, height);
        }
        
        currentImage.Dispose();
        currentImage = resized;
    }
    
    // ํšŒ์ „
    public void Rotate(float angle)
    {
        SaveState();
        
        Bitmap rotated = RotateImage(currentImage, angle);
        currentImage.Dispose();
        currentImage = rotated;
    }
    
    // ์ž๋ฅด๊ธฐ
    public void Crop(Rectangle area)
    {
        SaveState();
        
        Bitmap cropped = new Bitmap(area.Width, area.Height);
        using (Graphics g = Graphics.FromImage(cropped))
        {
            g.DrawImage(currentImage,
                       new Rectangle(0, 0, area.Width, area.Height),
                       area,
                       GraphicsUnit.Pixel);
        }
        
        currentImage.Dispose();
        currentImage = cropped;
    }
    
    // ๋ฐ๊ธฐ ์กฐ์ ˆ
    public void AdjustBrightness(int value)
    {
        SaveState();
        
        ColorMatrix matrix = new ColorMatrix(new float[][]
        {
            new float[] {1, 0, 0, 0, 0},
            new float[] {0, 1, 0, 0, 0},
            new float[] {0, 0, 1, 0, 0},
            new float[] {0, 0, 0, 1, 0},
            new float[] {value/255f, value/255f, value/255f, 0, 1}
        });
        
        ApplyColorMatrix(matrix);
    }
    
    // ๋Œ€๋น„ ์กฐ์ ˆ
    public void AdjustContrast(float value)
    {
        SaveState();
        
        float t = (1.0f - value) / 2.0f;
        ColorMatrix matrix = new ColorMatrix(new float[][]
        {
            new float[] {value, 0, 0, 0, 0},
            new float[] {0, value, 0, 0, 0},
            new float[] {0, 0, value, 0, 0},
            new float[] {0, 0, 0, 1, 0},
            new float[] {t, t, t, 0, 1}
        });
        
        ApplyColorMatrix(matrix);
    }
    
    // ์ฑ„๋„ ์กฐ์ ˆ
    public void AdjustSaturation(float saturation)
    {
        SaveState();
        
        float rWeight = 0.3086f;
        float gWeight = 0.6094f;
        float bWeight = 0.0820f;
        
        float a = (1.0f - saturation) * rWeight + saturation;
        float b = (1.0f - saturation) * rWeight;
        float c = (1.0f - saturation) * rWeight;
        float d = (1.0f - saturation) * gWeight;
        float e = (1.0f - saturation) * gWeight + saturation;
        float f = (1.0f - saturation) * gWeight;
        float g = (1.0f - saturation) * bWeight;
        float h = (1.0f - saturation) * bWeight;
        float i = (1.0f - saturation) * bWeight + saturation;
        
        ColorMatrix matrix = new ColorMatrix(new float[][]
        {
            new float[] {a, b, c, 0, 0},
            new float[] {d, e, f, 0, 0},
            new float[] {g, h, i, 0, 0},
            new float[] {0, 0, 0, 1, 0},
            new float[] {0, 0, 0, 0, 1}
        });
        
        ApplyColorMatrix(matrix);
    }
    
    // ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ
    public void ConvertToGrayscale()
    {
        SaveState();
        
        ColorMatrix matrix = new ColorMatrix(new float[][]
        {
            new float[] {0.299f, 0.299f, 0.299f, 0, 0},
            new float[] {0.587f, 0.587f, 0.587f, 0, 0},
            new float[] {0.114f, 0.114f, 0.114f, 0, 0},
            new float[] {0, 0, 0, 1, 0},
            new float[] {0, 0, 0, 0, 1}
        });
        
        ApplyColorMatrix(matrix);
    }
    
    // ์„ธํ”ผ์•„ ํšจ๊ณผ
    public void ApplySepia()
    {
        SaveState();
        
        ColorMatrix matrix = new ColorMatrix(new float[][]
        {
            new float[] {0.393f, 0.349f, 0.272f, 0, 0},
            new float[] {0.769f, 0.686f, 0.534f, 0, 0},
            new float[] {0.189f, 0.168f, 0.131f, 0, 0},
            new float[] {0, 0, 0, 1, 0},
            new float[] {0, 0, 0, 0, 1}
        });
        
        ApplyColorMatrix(matrix);
    }
    
    // ColorMatrix ์ ์šฉ ํ—ฌํผ ๋ฉ”์„œ๋“œ
    private void ApplyColorMatrix(ColorMatrix colorMatrix)
    {
        Bitmap result = new Bitmap(currentImage.Width, currentImage.Height);
        
        using (Graphics g = Graphics.FromImage(result))
        {
            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(colorMatrix);
            
            g.DrawImage(currentImage,
                       new Rectangle(0, 0, currentImage.Width, currentImage.Height),
                       0, 0, currentImage.Width, currentImage.Height,
                       GraphicsUnit.Pixel,
                       attributes);
        }
        
        currentImage.Dispose();
        currentImage = result;
    }
    
    // ํ…์ŠคํŠธ ์ถ”๊ฐ€
    public void AddText(string text, Font font, Color color, Point position)
    {
        SaveState();
        
        using (Graphics g = Graphics.FromImage(currentImage))
        {
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            using (SolidBrush brush = new SolidBrush(color))
            {
                g.DrawString(text, font, brush, position);
            }
        }
    }
    
    // ์›Œํ„ฐ๋งˆํฌ ์ถ”๊ฐ€
    public void AddWatermark(string text, Font font, Color color, float opacity = 0.5f)
    {
        SaveState();
        
        using (Graphics g = Graphics.FromImage(currentImage))
        {
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            
            SizeF textSize = g.MeasureString(text, font);
            float x = (currentImage.Width - textSize.Width) / 2;
            float y = (currentImage.Height - textSize.Height) / 2;
            
            Color watermarkColor = Color.FromArgb((int)(255 * opacity), color);
            using (SolidBrush brush = new SolidBrush(watermarkColor))
            {
                g.DrawString(text, font, brush, x, y);
            }
        }
    }
    
    // ์ €์žฅ
    public void Save(string filePath, ImageFormat format = null)
    {
        if (format == null)
        {
            string extension = System.IO.Path.GetExtension(filePath).ToLower();
            format = extension switch
            {
                ".jpg" or ".jpeg" => ImageFormat.Jpeg,
                ".png" => ImageFormat.Png,
                ".bmp" => ImageFormat.Bmp,
                ".gif" => ImageFormat.Gif,
                ".tiff" => ImageFormat.Tiff,
                _ => ImageFormat.Png
            };
        }
        
        currentImage.Save(filePath, format);
    }
    
    // JPEG ํ’ˆ์งˆ ์ง€์ • ์ €์žฅ
    public void SaveJpeg(string filePath, long quality)
    {
        ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
        EncoderParameters encoderParams = new EncoderParameters(1);
        encoderParams.Param[0] = new EncoderParameter(
            System.Drawing.Imaging.Encoder.Quality, quality);
        
        currentImage.Save(filePath, jpegCodec, encoderParams);
    }
    
    // ์ฝ”๋ฑ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
    private ImageCodecInfo GetEncoderInfo(string mimeType)
    {
        ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
        foreach (ImageCodecInfo codec in codecs)
        {
            if (codec.MimeType == mimeType)
                return codec;
        }
        return null;
    }
    
    // ํšŒ์ „ ํ—ฌํผ ๋ฉ”์„œ๋“œ
    private Bitmap RotateImage(Bitmap original, float angle)
    {
        double radians = angle * Math.PI / 180;
        double cos = Math.Abs(Math.Cos(radians));
        double sin = Math.Abs(Math.Sin(radians));
        
        int newWidth = (int)(original.Width * cos + original.Height * sin);
        int newHeight = (int)(original.Width * sin + original.Height * cos);
        
        Bitmap rotated = new Bitmap(newWidth, newHeight);
        
        using (Graphics g = Graphics.FromImage(rotated))
        {
            g.Clear(Color.Transparent);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.TranslateTransform(newWidth / 2f, newHeight / 2f);
            g.RotateTransform(angle);
            g.TranslateTransform(-original.Width / 2f, -original.Height / 2f);
            g.DrawImage(original, new Point(0, 0));
        }
        
        return rotated;
    }
    
    // ๋ฆฌ์†Œ์Šค ์ •๋ฆฌ
    public void Dispose()
    {
        currentImage?.Dispose();
        
        while (undoStack.Count > 0)
            undoStack.Pop().Dispose();
        
        while (redoStack.Count > 0)
            redoStack.Pop().Dispose();
    }
}

โœจ ์‚ฌ์šฉ ์˜ˆ์ œ:

// ImageProcessor ์‚ฌ์šฉํ•˜๊ธฐ
ImageProcessor processor = new ImageProcessor();

try
{
    // ์ด๋ฏธ์ง€ ๋กœ๋“œ
    processor.LoadImage(@"C:\Images\photo.jpg");
    
    // ํฌ๊ธฐ ์กฐ์ ˆ (๋น„์œจ ์œ ์ง€)
    processor.Resize(800, 600, keepAspectRatio: true);
    
    // ๋ฐ๊ธฐ ์ฆ๊ฐ€
    processor.AdjustBrightness(20);
    
    // ๋Œ€๋น„ ์ฆ๊ฐ€
    processor.AdjustContrast(1.2f);
    
    // ์›Œํ„ฐ๋งˆํฌ ์ถ”๊ฐ€
    using (Font font = new Font("Arial", 24, FontStyle.Bold))
    {
        processor.AddWatermark("ยฉ 2024 MyPhoto", font, Color.White, 0.3f);
    }
    
    // ์ €์žฅ (๊ณ ํ’ˆ์งˆ JPEG)
    processor.SaveJpeg(@"C:\Images\edited.jpg", 95);
    
    Console.WriteLine("์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์™„๋ฃŒ!");
}
finally
{
    processor.Dispose();
}

๐ŸŽฏ WinForms์™€ ํ†ตํ•ฉํ•˜๊ธฐ

์ด์ œ ๋งŒ๋“  ImageProcessor๋ฅผ ์‹ค์ œ Windows Forms ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ํ†ตํ•ฉํ•ด๋ณด์ž!

๐Ÿ–ฅ๏ธ ๊ฐ„๋‹จํ•œ ์ด๋ฏธ์ง€ ๋ทฐ์–ด ๋งŒ๋“ค๊ธฐ

using System;
using System.Drawing;
using System.Windows.Forms;

public class ImageViewerForm : Form
{
    private PictureBox pictureBox;
    private MenuStrip menuStrip;
    private ImageProcessor processor;
    private string currentFilePath;
    
    public ImageViewerForm()
    {
        InitializeComponents();
        processor = new ImageProcessor();
    }
    
    private void InitializeComponents()
    {
        // ํผ ์„ค์ •
        this.Text = "C# Image Viewer";
        this.Size = new Size(1000, 700);
        this.StartPosition = FormStartPosition.CenterScreen;
        
        // ๋ฉ”๋‰ด ์ŠคํŠธ๋ฆฝ
        menuStrip = new MenuStrip();
        
        // ํŒŒ์ผ ๋ฉ”๋‰ด
        ToolStripMenuItem fileMenu = new ToolStripMenuItem("ํŒŒ์ผ(&F)");
        fileMenu.DropDownItems.Add("์—ด๊ธฐ(&O)", null, OnOpenClick);
        fileMenu.DropDownItems.Add("์ €์žฅ(&S)", null, OnSaveClick);
        fileMenu.DropDownItems.Add("๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ์ €์žฅ(&A)", null, OnSaveAsClick);
        fileMenu.DropDownItems.Add(new ToolStripSeparator());
        fileMenu.DropDownItems.Add("์ข…๋ฃŒ(&X)", null, (s, e) => this.Close());
        
        // ํŽธ์ง‘ ๋ฉ”๋‰ด
        ToolStripMenuItem editMenu = new ToolStripMenuItem("ํŽธ์ง‘(&E)");
        editMenu.DropDownItems.Add("์‹คํ–‰ ์ทจ์†Œ(&U)", null, OnUndoClick);
        editMenu.DropDownItems.Add("๋‹ค์‹œ ์‹คํ–‰(&R)", null, OnRedoClick);
        editMenu.DropDownItems.Add(new ToolStripSeparator());
        editMenu.DropDownItems.Add("ํฌ๊ธฐ ์กฐ์ ˆ(&S)", null, OnResizeClick);
        editMenu.DropDownItems.Add("ํšŒ์ „(&T)", null, OnRotateClick);
        editMenu.DropDownItems.Add("์ž๋ฅด๊ธฐ(&C)", null, OnCropClick);
        
        // ํšจ๊ณผ ๋ฉ”๋‰ด
        ToolStripMenuItem effectMenu = new ToolStripMenuItem("ํšจ๊ณผ(&X)");
        effectMenu.DropDownItems.Add("๋ฐ๊ธฐ/๋Œ€๋น„(&B)", null, OnBrightnessContrastClick);
        effectMenu.DropDownItems.Add("์ฑ„๋„(&S)", null, OnSaturationClick);
        effectMenu.DropDownItems.Add(new ToolStripSeparator());
        effectMenu.DropDownItems.Add("๊ทธ๋ ˆ์ด์Šค์ผ€์ผ(&G)", null, OnGrayscaleClick);
        effectMenu.DropDownItems.Add("์„ธํ”ผ์•„(&P)", null, OnSepiaClick);
        effectMenu.DropDownItems.Add(new ToolStripSeparator());
        effectMenu.DropDownItems.Add("์›Œํ„ฐ๋งˆํฌ ์ถ”๊ฐ€(&W)", null, OnWatermarkClick);
        
        menuStrip.Items.Add(fileMenu);
        menuStrip.Items.Add(editMenu);
        menuStrip.Items.Add(effectMenu);
        
        // PictureBox
        pictureBox = new PictureBox
        {
            Dock = DockStyle.Fill,
            SizeMode = PictureBoxSizeMode.Zoom,
            BackColor = Color.DarkGray
        };
        
        // ์ปจํŠธ๋กค ์ถ”๊ฐ€
        this.Controls.Add(pictureBox);
        this.Controls.Add(menuStrip);
        this.MainMenuStrip = menuStrip;
    }
    
    private void OnOpenClick(object sender, EventArgs e)
    {
        using (OpenFileDialog dialog = new OpenFileDialog())
        {
            dialog.Filter = "์ด๋ฏธ์ง€ ํŒŒ์ผ|*.jpg;*.jpeg;*.png;*.bmp;*.gif|๋ชจ๋“  ํŒŒ์ผ|*.*";
            
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    currentFilePath = dialog.FileName;
                    processor.LoadImage(currentFilePath);
                    UpdateDisplay();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"์ด๋ฏธ์ง€๋ฅผ ์—ด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {ex.Message}", 
                                  "์˜ค๋ฅ˜", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
    }
    
    private void OnSaveClick(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(currentFilePath))
        {
            OnSaveAsClick(sender, e);
            return;
        }
        
        try
        {
            processor.Save(currentFilePath);
            MessageBox.Show("์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!", "์™„๋ฃŒ", 
                          MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show($"์ €์žฅ ์‹คํŒจ: {ex.Message}", 
                          "์˜ค๋ฅ˜", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
    
    private void OnSaveAsClick(object sender, EventArgs e)
    {
        using (SaveFileDialog dialog = new SaveFileDialog())
        {
            dialog.Filter = "JPEG|*.jpg|PNG|*.png|BMP|*.bmp|๋ชจ๋“  ํŒŒ์ผ|*.*";
            
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    processor.Save(dialog.FileName);
                    currentFilePath = dialog.FileName;
                    MessageBox.Show("์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!", "์™„๋ฃŒ", 
                                  MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"์ €์žฅ ์‹คํŒจ: {ex.Message}", 
                                  "์˜ค๋ฅ˜", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
    }
    
    private void OnUndoClick(object sender, EventArgs e)
    {
        processor.Undo();
        UpdateDisplay();
    }
    
    private void OnRedoClick(object sender, EventArgs e)
    {
        processor.Redo();
        UpdateDisplay();
    }
    
    private void OnResizeClick(object sender, EventArgs e)
    {
        using (ResizeDialog dialog = new ResizeDialog())
        {
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                processor.Resize(dialog.NewWidth, dialog.NewHeight, dialog.KeepAspectRatio);
                UpdateDisplay();
            }
        }
    }
    
    private void OnRotateClick(object sender, EventArgs e)
    {
        string input = Microsoft.VisualBasic.Interaction.InputBox(
            "ํšŒ์ „ ๊ฐ๋„๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” (๋„):", "ํšŒ์ „", "90");
        
        if (float.TryParse(input, out float angle))
        {
            processor.Rotate(angle);
            UpdateDisplay();
        }
    }
    
    private void OnCropClick(object sender, EventArgs e)
    {
        MessageBox.Show("์ž๋ฅด๊ธฐ ๊ธฐ๋Šฅ์€ ๋งˆ์šฐ์Šค ๋“œ๋ž˜๊ทธ๋กœ ์˜์—ญ์„ ์„ ํƒํ•œ ํ›„ ์‚ฌ์šฉํ•˜์„ธ์š”.", 
                       "์•ˆ๋‚ด", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    
    private void OnBrightnessContrastClick(object sender, EventArgs e)
    {
        using (BrightnessContrastDialog dialog = new BrightnessContrastDialog())
        {
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                processor.AdjustBrightness(dialog.Brightness);
                processor.AdjustContrast(dialog.Contrast);
                UpdateDisplay();
            }
        }
    }
    
    private void OnSaturationClick(object sender, EventArgs e)
    {
        string input = Microsoft.VisualBasic.Interaction.InputBox(
            "์ฑ„๋„ ๊ฐ’์„ ์ž…๋ ฅํ•˜์„ธ์š” (0.0 ~ 2.0):", "์ฑ„๋„ ์กฐ์ ˆ", "1.0");
        
        if (float.TryParse(input, out float saturation))
        {
            processor.AdjustSaturation(saturation);
            UpdateDisplay();
        }
    }
    
    private void OnGrayscaleClick(object sender, EventArgs e)
    {
        processor.ConvertToGrayscale();
        UpdateDisplay();
    }
    
    private void OnSepiaClick(object sender, EventArgs e)
    {
        processor.ApplySepia();
        UpdateDisplay();
    }
    
    private void OnWatermarkClick(object sender, EventArgs e)
    {
        string text = Microsoft.VisualBasic.Interaction.InputBox(
            "์›Œํ„ฐ๋งˆํฌ ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”:", "์›Œํ„ฐ๋งˆํฌ", "ยฉ 2024");
        
        if (!string.IsNullOrEmpty(text))
        {
            using (Font font = new Font("Arial", 24, FontStyle.Bold))
            {
                processor.AddWatermark(text, font, Color.White, 0.3f);
                UpdateDisplay();
            }
        }
    }
    
    private void UpdateDisplay()
    {
        if (pictureBox.Image != null)
            pictureBox.Image.Dispose();
        
        pictureBox.Image = processor.GetCurrentImage();
    }
    
    protected override void OnFormClosing(FormClosingEventArgs e)
    {
        processor?.Dispose();
        pictureBox.Image?.Dispose();
        base.OnFormClosing(e);
    }
}

// ํ”„๋กœ๊ทธ๋žจ ์ง„์ž…์ 
static class Program
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new ImageViewerForm());
    }
}

๐Ÿ’ก ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ์•„์ด๋””์–ด: โ€ข ๋งˆ์šฐ์Šค ๋“œ๋ž˜๊ทธ๋กœ ์ž๋ฅด๊ธฐ ์˜์—ญ ์„ ํƒ
โ€ข ์‹ค์‹œ๊ฐ„ ํ•„ํ„ฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
โ€ข ํžˆ์Šคํ† ๊ทธ๋žจ ํ‘œ์‹œ
โ€ข ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ (์—ฌ๋Ÿฌ ์ด๋ฏธ์ง€ ๋™์‹œ ํŽธ์ง‘)
โ€ข ๋ ˆ์ด์–ด ๊ธฐ๋Šฅ
โ€ข ํ”Œ๋Ÿฌ๊ทธ์ธ ์‹œ์Šคํ…œ
โ€ข ํด๋ฆฝ๋ณด๋“œ ์ง€์› (๋ณต์‚ฌ/๋ถ™์—ฌ๋„ฃ๊ธฐ)

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™” ํŒ

์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ๋Š” CPU๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ์ž‘์—…์ด์•ผ. ์„ฑ๋Šฅ์„ ์ตœ์ ํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•๋“ค์„ ์•Œ์•„๋ณด์ž!

๐Ÿš€ 1. LockBits ์‚ฌ์šฉํ•˜๊ธฐ

์•ž์—์„œ๋„ ์–ธ๊ธ‰ํ–ˆ์ง€๋งŒ, GetPixel/SetPixel ๋Œ€์‹  LockBits๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์—„์ฒญ๋‚œ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์–ป์„ ์ˆ˜ ์žˆ์–ด:

์„ฑ๋Šฅ ๋น„๊ต (1920x1080 ์ด๋ฏธ์ง€ ๊ธฐ์ค€):
โ€ข GetPixel/SetPixel: ์•ฝ 2,500ms
โ€ข LockBits: ์•ฝ 80ms
โ€ข ์„ฑ๋Šฅ ํ–ฅ์ƒ: ์•ฝ 31๋ฐฐ!


๐Ÿ”ง 2. ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ํ™œ์šฉ

using System.Threading.Tasks;

public Bitmap ParallelGrayscale(Bitmap original)
{
    Bitmap grayscale = new Bitmap(original.Width, original.Height);
    
    Rectangle rect = new Rectangle(0, 0, original.Width, original.Height);
    BitmapData originalData = original.LockBits(rect, ImageLockMode.ReadOnly, 
                                                 PixelFormat.Format24bppRgb);
    BitmapData grayscaleData = grayscale.LockBits(rect, ImageLockMode.WriteOnly, 
                                                   PixelFormat.Format24bppRgb);
    
    int bytes = Math.Abs(originalData.Stride) * original.Height;
    byte[] rgbValues = new byte[bytes];
    byte[] grayValues = new byte[bytes];
    
    System.Runtime.InteropServices.Marshal.Copy(originalData.Scan0, rgbValues, 0, bytes);
    
    // ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ
    Parallel.For(0, original.Height, y =>
    {
        int offset = y * Math.Abs(originalData.Stride);
        
        for (int x = 0; x < original.Width; x++)
        {
            int index = offset + x * 3;
            
            byte gray = (byte)(rgbValues[index] * 0.114 +      // Blue
                              rgbValues[index + 1] * 0.587 +   // Green
                              rgbValues[index + 2] * 0.299);   // Red
            
            grayValues[index] = gray;
            grayValues[index + 1] = gray;
            grayValues[index + 2] = gray;
        }
    });
    
    System.Runtime.InteropServices.Marshal.Copy(grayValues, 0, grayscaleData.Scan0, bytes);
    
    original.UnlockBits(originalData);
    grayscale.UnlockBits(grayscaleData);
    
    return grayscale;
}

โœจ ์„ฑ๋Šฅ ํ–ฅ์ƒ: ๋ฉ€ํ‹ฐ์ฝ”์–ด CPU์—์„œ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ถ”๊ฐ€๋กœ 2~4๋ฐฐ ์ •๋„ ์„ฑ๋Šฅ์ด ํ–ฅ์ƒ๋ผ. 4์ฝ”์–ด CPU์—์„œ๋Š” ์•ฝ 3๋ฐฐ, 8์ฝ”์–ด์—์„œ๋Š” ์•ฝ 5๋ฐฐ๊นŒ์ง€ ๋นจ๋ผ์งˆ ์ˆ˜ ์žˆ์–ด!


๐Ÿ’พ 3. ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ

// ๋‚˜์œ ์˜ˆ: ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ๋ฐœ์ƒ
public void BadExample()
{
    for (int i = 0; i < 100; i++)
    {
        Bitmap img = new Bitmap(1000, 1000);
        // img.Dispose()๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š์Œ!
    }
}

// ์ข‹์€ ์˜ˆ: ์˜ฌ๋ฐ”๋ฅธ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ
public void GoodExample()
{
    for (int i = 0; i < 100; i++)
    {
        using (Bitmap img = new Bitmap(1000, 1000))
        {
            // ์ž‘์—… ์ˆ˜ํ–‰
        } // using ๋ธ”๋ก์„ ๋ฒ—์–ด๋‚˜๋ฉด ์ž๋™์œผ๋กœ Dispose ํ˜ธ์ถœ
    }
}

// ๋” ์ข‹์€ ์˜ˆ: ๊ฐ์ฒด ์žฌ์‚ฌ์šฉ
public void BetterExample()
{
    Bitmap img = new Bitmap(1000, 1000);
    
    try
    {
        for (int i = 0; i < 100; i++)
        {
            using (Graphics g = Graphics.FromImage(img))
            {
                g.Clear(Color.White);
                // ์ž‘์—… ์ˆ˜ํ–‰
            }
        }
    }
    finally
    {
        img.Dispose();
    }
}


๐Ÿ“Š 4. ์ ์ ˆํ•œ ์ด๋ฏธ์ง€ ํฌ๋งท ์„ ํƒ

JPEG ๐Ÿ“ท
โ€ข ์†์‹ค ์••์ถ•
โ€ข ์‚ฌ์ง„์— ์ ํ•ฉ
โ€ข ์ž‘์€ ํŒŒ์ผ ํฌ๊ธฐ
โ€ข ํˆฌ๋ช…๋„ ๋ฏธ์ง€์›

PNG ๐ŸŽจ
โ€ข ๋ฌด์†์‹ค ์••์ถ•
โ€ข ํˆฌ๋ช…๋„ ์ง€์›
โ€ข ๊ทธ๋ž˜ํ”ฝ์— ์ ํ•ฉ
โ€ข ํฐ ํŒŒ์ผ ํฌ๊ธฐ

BMP ๐Ÿ–ผ๏ธ
โ€ข ์••์ถ• ์—†์Œ
โ€ข ๋น ๋ฅธ ์ฒ˜๋ฆฌ
โ€ข ๋งค์šฐ ํฐ ํฌ๊ธฐ
โ€ข ์ž„์‹œ ํŒŒ์ผ์šฉ

GIF ๐ŸŽฌ
โ€ข 256์ƒ‰ ์ œํ•œ
โ€ข ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ง€์›
โ€ข ํˆฌ๋ช…๋„ ์ง€์›
โ€ข ๋‹จ์ˆœ ๊ทธ๋ž˜ํ”ฝ์šฉ


โš™๏ธ 5. Graphics ํ’ˆ์งˆ ์„ค์ • ์ตœ์ ํ™”

// ๊ณ ํ’ˆ์งˆ ์„ค์ • (๋А๋ฆผ)
public void HighQualitySettings(Graphics g)
{
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g.SmoothingMode = SmoothingMode.HighQuality;
    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
    g.CompositingQuality = CompositingQuality.HighQuality;
}

// ๊ท ํ˜•์žกํžŒ ์„ค์ • (๊ถŒ์žฅ)
public void BalancedSettings(Graphics g)
{
    g.InterpolationMode = InterpolationMode.Bilinear;
    g.SmoothingMode = SmoothingMode.AntiAlias;
    g.PixelOffsetMode = PixelOffsetMode.Half;
    g.CompositingQuality = CompositingQuality.AssumeLinear;
}

// ๊ณ ์† ์„ค์ • (๋น ๋ฆ„)
public void FastSettings(Graphics g)
{
    g.InterpolationMode = InterpolationMode.NearestNeighbor;
    g.SmoothingMode = SmoothingMode.None;
    g.PixelOffsetMode = PixelOffsetMode.Default;
    g.CompositingQuality = CompositingQuality.HighSpeed;
}

๐Ÿ”ฎ .NET Core/.NET 5+ ํ™˜๊ฒฝ์—์„œ์˜ System.Drawing

.NET Core์™€ .NET 5 ์ด์ƒ์—์„œ๋Š” System.Drawing์— ๋ช‡ ๊ฐ€์ง€ ๋ณ€ํ™”๊ฐ€ ์žˆ์–ด. ์•Œ์•„๋‘๋ฉด ์ข‹์„ ๋‚ด์šฉ๋“ค์„ ์ •๋ฆฌํ•ด๋ณผ๊ฒŒ!

โš ๏ธ System.Drawing.Common์˜ ๋ณ€ํ™”

์ค‘์š”ํ•œ ๋ณ€๊ฒฝ์‚ฌํ•ญ: .NET 6๋ถ€ํ„ฐ System.Drawing.Common์€ Windows์—์„œ๋งŒ ์ง€์›๋ผ. Linux์™€ macOS์—์„œ๋Š” ๋Ÿฐํƒ€์ž„ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด.

ํฌ๋กœ์Šค ํ”Œ๋žซํผ ๊ฐœ๋ฐœ์„ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ ๋Œ€์•ˆ๋“ค์„ ๊ณ ๋ คํ•ด์•ผ ํ•ด:

โ€ข ImageSharp - ์ˆœ์ˆ˜ C#๋กœ ์ž‘์„ฑ๋œ ํฌ๋กœ์Šค ํ”Œ๋žซํผ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
โ€ข SkiaSharp - Google์˜ Skia ๊ทธ๋ž˜ํ”ฝ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ .NET ๋ฐ”์ธ๋”ฉ
โ€ข Magick.NET - ImageMagick์˜ .NET ๋ž˜ํผ


๐Ÿ”ง System.Drawing.Common ์‚ฌ์šฉ ์„ค์ •

// .csproj ํŒŒ์ผ์— ์ถ”๊ฐ€
<PropertyGroup>
  <TargetFramework>net6.0</TargetFramework>
  <!-- Windows์—์„œ๋งŒ System.Drawing.Common ์‚ฌ์šฉ ํ—ˆ์šฉ -->
  <EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>


๐ŸŽจ ImageSharp ์‚ฌ์šฉ ์˜ˆ์ œ

ํฌ๋กœ์Šค ํ”Œ๋žซํผ์ด ํ•„์š”ํ•˜๋‹ค๋ฉด ImageSharp์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์€ ์„ ํƒ์ด์•ผ:

// NuGet ํŒจํ‚ค์ง€ ์„ค์น˜: SixLabors.ImageSharp

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats;

// ์ด๋ฏธ์ง€ ๋กœ๋“œ ๋ฐ ์ฒ˜๋ฆฌ
using (Image<Rgba32> image = Image.Load<Rgba32>("input.jpg"))
{
    // ํฌ๊ธฐ ์กฐ์ ˆ
    image.Mutate(x => x.Resize(800, 600));
    
    // ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ
    image.Mutate(x => x.Grayscale());
    
    // ํšŒ์ „
    image.Mutate(x => x.Rotate(45));
    
    // ๋ฐ๊ธฐ ์กฐ์ ˆ
    image.Mutate(x => x.Brightness(1.2f));
    
    // ์ €์žฅ
    image.Save("output.jpg");
}

// ํ…์ŠคํŠธ ์ถ”๊ฐ€
using (Image<Rgba32> image = Image.Load<Rgba32>("input.jpg"))
{
    image.Mutate(x => x.DrawText(
        "Hello ImageSharp!",
        SystemFonts.CreateFont("Arial", 48),
        Color.White,
        new PointF(100, 100)
    ));
    
    image.Save("output.jpg");
}

๐Ÿ’ก ImageSharp vs System.Drawing: ImageSharp ์žฅ์ :
โ€ข ํฌ๋กœ์Šค ํ”Œ๋žซํผ ์ง€์›
โ€ข ํ˜„๋Œ€์ ์ธ API ๋””์ž์ธ
โ€ข ํ™œ๋ฐœํ•œ ๊ฐœ๋ฐœ๊ณผ ์—…๋ฐ์ดํŠธ
โ€ข ๋” ๋‚˜์€ ์„ฑ๋Šฅ (์ผ๋ถ€ ์ž‘์—…์—์„œ)

System.Drawing ์žฅ์ :
โ€ข Windows์—์„œ ๊ฒ€์ฆ๋œ ์•ˆ์ •์„ฑ
โ€ข ๋ฐฉ๋Œ€ํ•œ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ์™€ ์˜ˆ์ œ
โ€ข GDI+์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ ์ ‘๊ทผ
โ€ข ์ถ”๊ฐ€ ํŒจํ‚ค์ง€ ์„ค์น˜ ๋ถˆํ•„์š” (.NET Framework)

๐ŸŽ“ ์‹ค์ „ ํ™œ์šฉ ์‚ฌ๋ก€

์ด์ œ ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ช‡ ๊ฐ€์ง€ ์‚ฌ๋ก€๋ฅผ ์‚ดํŽด๋ณด์ž!

๐Ÿ“ธ 1. ์ธ๋„ค์ผ ์ƒ์„ฑ๊ธฐ

public class ThumbnailGenerator
{
    public void GenerateThumbnails(string sourceFolder, string targetFolder, 
                                   int maxWidth, int maxHeight)
    {
        if (!Directory.Exists(targetFolder))
            Directory.CreateDirectory(targetFolder);
        
        string[] imageFiles = Directory.GetFiles(sourceFolder, "*.*")
            .Where(f => f.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||
                       f.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
                       f.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
            .ToArray();
        
        Parallel.ForEach(imageFiles, imageFile =>
        {
            try
            {
                using (Image original = Image.FromFile(imageFile))
                {
                    // ๋น„์œจ ์œ ์ง€ํ•˜๋ฉฐ ํฌ๊ธฐ ๊ณ„์‚ฐ
                    double ratioX = (double)maxWidth / original.Width;
                    double ratioY = (double)maxHeight / original.Height;
                    double ratio = Math.Min(ratioX, ratioY);
                    
                    int newWidth = (int)(original.Width * ratio);
                    int newHeight = (int)(original.Height * ratio);
                    
                    using (Bitmap thumbnail = new Bitmap(newWidth, newHeight))
                    {
                        using (Graphics g = Graphics.FromImage(thumbnail))
                        {
                            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            g.DrawImage(original, 0, 0, newWidth, newHeight);
                        }
                        
                        string fileName = Path.GetFileName(imageFile);
                        string targetPath = Path.Combine(targetFolder, 
                                          $"thumb_{fileName}");
                        
                        thumbnail.Save(targetPath, ImageFormat.Jpeg);
                    }
                }
                
                Console.WriteLine($"์ƒ์„ฑ ์™„๋ฃŒ: {Path.GetFileName(imageFile)}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"์˜ค๋ฅ˜ ({Path.GetFileName(imageFile)}): {ex.Message}");
            }
        });
    }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
ThumbnailGenerator generator = new ThumbnailGenerator();
generator.GenerateThumbnails(@"C:\Photos", @"C:\Thumbnails", 200, 200);


๐Ÿ–ผ๏ธ 2. ์ด๋ฏธ์ง€ ์›Œํ„ฐ๋งˆํฌ ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ

public class WatermarkProcessor
{
    private string watermarkText;
    private Font watermarkFont;
    private Color watermarkColor;
    private float opacity;
    
    public WatermarkProcessor(string text, Font font, Color color, float opacity = 0.3f)
    {
        this.watermarkText = text;
        this.watermarkFont = font;
        this.watermarkColor = color;
        this.opacity = opacity;
    }
    
    public void ProcessFolder(string sourceFolder, string targetFolder)
    {
        if (!Directory.Exists(targetFolder))
            Directory.CreateDirectory(targetFolder);
        
        string[] imageFiles = Directory.GetFiles(sourceFolder, "*.jpg");
        
        foreach (string imageFile in imageFiles)
        {
            try
            {
                using (Bitmap original = new Bitmap(imageFile))
                using (Bitmap watermarked = AddWatermark(original))
                {
                    string fileName = Path.GetFileName(imageFile);
                    string targetPath = Path.Combine(targetFolder, fileName);
                    
                    // JPEG ํ’ˆ์งˆ 90์œผ๋กœ ์ €์žฅ
                    SaveJpeg(watermarked, targetPath, 90);
                }
                
                Console.WriteLine($"์ฒ˜๋ฆฌ ์™„๋ฃŒ: {Path.GetFileName(imageFile)}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"์˜ค๋ฅ˜: {ex.Message}");
            }
        }
    }
    
    private Bitmap AddWatermark(Bitmap original)
    {
        Bitmap result = (Bitmap)original.Clone();
        
        using (Graphics g = Graphics.FromImage(result))
        {
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            
            // ํ…์ŠคํŠธ ํฌ๊ธฐ ์ธก์ •
            SizeF textSize = g.MeasureString(watermarkText, watermarkFont);
            
            // ์šฐ์ธก ํ•˜๋‹จ์— ๋ฐฐ์น˜
            float x = result.Width - textSize.Width - 20;
            float y = result.Height - textSize.Height - 20;
            
            // ๋ฐ˜ํˆฌ๋ช… ์ƒ‰์ƒ
            Color color = Color.FromArgb((int)(255 * opacity), watermarkColor);
            
            using (SolidBrush brush = new SolidBrush(color))
            {
                g.DrawString(watermarkText, watermarkFont, brush, x, y);
            }
        }
        
        return result;
    }
    
    private void SaveJpeg(Bitmap image, string filePath, long quality)
    {
        ImageCodecInfo jpegCodec = ImageCodecInfo.GetImageEncoders()
            .First(c => c.MimeType == "image/jpeg");
        
        EncoderParameters encoderParams = new EncoderParameters(1);
        encoderParams.Param[0] = new EncoderParameter(
            System.Drawing.Imaging.Encoder.Quality, quality);
        
        image.Save(filePath, jpegCodec, encoderParams);
    }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
using (Font font = new Font("Arial", 24, FontStyle.Bold))
{
    WatermarkProcessor processor = new WatermarkProcessor(
        "ยฉ 2024 MyCompany", font, Color.White, 0.5f);
    
    processor.ProcessFolder(@"C:\OriginalPhotos", @"C:\WatermarkedPhotos");
}


๐Ÿ“Š 3. ์ฐจํŠธ ์ƒ์„ฑ๊ธฐ

public class SimpleChartGenerator
{
    public Bitmap CreateBarChart(string title, Dictionary<string, double> data, 
                                 int width = 800, int height = 600)
    {
        Bitmap chart = new Bitmap(width, height);
        
        using (Graphics g = Graphics.FromImage(chart))
        {
            g.Clear(Color.White);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            
            // ์—ฌ๋ฐฑ ์„ค์ •
            int marginLeft = 80;
            int marginRight = 40;
            int marginTop = 80;
            int marginBottom = 80;
            
            int chartWidth = width - marginLeft - marginRight;
            int chartHeight = height - marginTop - marginBottom;
            
            // ์ œ๋ชฉ ๊ทธ๋ฆฌ๊ธฐ
            using (Font titleFont = new Font("๋ง‘์€ ๊ณ ๋”•", 24, FontStyle.Bold))
            using (SolidBrush blackBrush = new SolidBrush(Color.Black))
            {
                SizeF titleSize = g.MeasureString(title, titleFont);
                float titleX = (width - titleSize.Width) / 2;
                g.DrawString(title, titleFont, blackBrush, titleX, 20);
            }
            
            // ์ตœ๋Œ€๊ฐ’ ์ฐพ๊ธฐ
            double maxValue = data.Values.Max();
            
            // ๋ง‰๋Œ€ ๊ทธ๋ฆฌ๊ธฐ
            int barCount = data.Count;
            int barWidth = chartWidth / barCount - 20;
            int barSpacing = 20;
            
            using (Font labelFont = new Font("๋ง‘์€ ๊ณ ๋”•", 10))
            using (SolidBrush blackBrush = new SolidBrush(Color.Black))
            {
                int index = 0;
                foreach (var item in data)
                {
                    // ๋ง‰๋Œ€ ๋†’์ด ๊ณ„์‚ฐ
                    int barHeight = (int)(item.Value / maxValue * chartHeight);
                    
                    // ๋ง‰๋Œ€ ์œ„์น˜
                    int x = marginLeft + index * (barWidth + barSpacing);
                    int y = marginTop + chartHeight - barHeight;
                    
                    // ๋ง‰๋Œ€ ์ƒ‰์ƒ (๊ทธ๋ผ๋””์–ธํŠธ)
                    using (LinearGradientBrush barBrush = new LinearGradientBrush(
                        new Rectangle(x, y, barWidth, barHeight),
                        Color.FromArgb(100, 150, 255),
                        Color.FromArgb(50, 100, 200),
                        LinearGradientMode.Vertical))
                    {
                        g.FillRectangle(barBrush, x, y, barWidth, barHeight);
                    }
                    
                    // ํ…Œ๋‘๋ฆฌ
                    using (Pen borderPen = new Pen(Color.FromArgb(30, 80, 180), 2))
                    {
                        g.DrawRectangle(borderPen, x, y, barWidth, barHeight);
                    }
                    
                    // ๊ฐ’ ํ‘œ์‹œ
                    string valueText = item.Value.ToString("F1");
                    SizeF valueSize = g.MeasureString(valueText, labelFont);
                    g.DrawString(valueText, labelFont, blackBrush,
                               x + (barWidth - valueSize.Width) / 2,
                               y - valueSize.Height - 5);
                    
                    // ๋ ˆ์ด๋ธ” ํ‘œ์‹œ
                    SizeF labelSize = g.MeasureString(item.Key, labelFont);
                    g.DrawString(item.Key, labelFont, blackBrush,
                               x + (barWidth - labelSize.Width) / 2,
                               marginTop + chartHeight + 10);
                    
                    index++;
                }
            }
            
            // ์ถ• ๊ทธ๋ฆฌ๊ธฐ
            using (Pen axisPen = new Pen(Color.Black, 2))
            {
                // Y์ถ•
                g.DrawLine(axisPen, marginLeft, marginTop, 
                          marginLeft, marginTop + chartHeight);
                
                // X์ถ•
                g.DrawLine(axisPen, marginLeft, marginTop + chartHeight,
                          marginLeft + chartWidth, marginTop + chartHeight);
            }
            
            // Y์ถ• ๋ˆˆ๊ธˆ
            using (Font axisFont = new Font("๋ง‘์€ ๊ณ ๋”•", 9))
            using (SolidBrush blackBrush = new SolidBrush(Color.Black))
            using (Pen gridPen = new Pen(Color.LightGray, 1))
            {
                gridPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                
                for (int i = 0; i <= 5; i++)
                {
                    double value = maxValue * i / 5;
                    int y = marginTop + chartHeight - (int)(chartHeight * i / 5.0);
                    
                    // ๋ˆˆ๊ธˆ ์„ 
                    g.DrawLine(gridPen, marginLeft, y, 
                              marginLeft + chartWidth, y);
                    
                    // ๋ˆˆ๊ธˆ ๊ฐ’
                    string label = value.ToString("F0");
                    SizeF labelSize = g.MeasureString(label, axisFont);
                    g.DrawString(label, axisFont, blackBrush,
                               marginLeft - labelSize.Width - 10,
                               y - labelSize.Height / 2);
                }
            }
        }
        
        return chart;
    }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
SimpleChartGenerator generator = new SimpleChartGenerator();

Dictionary<string, double> salesData = new Dictionary<string, double>
{
    { "1์›”", 150.5 },
    { "2์›”", 200.3 },
    { "3์›”", 180.7 },
    { "4์›”", 220.1 },
    { "5์›”", 250.8 },
    { "6์›”", 280.4 }
};

using (Bitmap chart = generator.CreateBarChart("์›”๋ณ„ ๋งค์ถœ ํ˜„ํ™ฉ", salesData))
{
    chart.Save(@"C:\Charts\sales_chart.png", ImageFormat.Png);
}

โœจ ์žฌ๋Šฅ๋„ท(https://www.jaenung.net)์—์„œ ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”๋‚˜ ๋ฆฌํฌํŠธ ์ƒ์„ฑ ์žฌ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๋ถ„๋“ค์ด ์ด๋Ÿฐ ์ฐจํŠธ ์ƒ์„ฑ ๊ธฐ๋Šฅ์„ ๋งŽ์ด ํ™œ์šฉํ•ด. ์ž๋™ํ™”๋œ ๋ฆฌํฌํŠธ ์‹œ์Šคํ…œ์„ ๋งŒ๋“ค ๋•Œ ์ •๋ง ์œ ์šฉํ•˜๊ฑฐ๋“ !

๐Ÿ› ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์™€ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋‹ค ๋ณด๋ฉด ์ž์ฃผ ๋งˆ์ฃผ์น˜๋Š” ๋ฌธ์ œ๋“ค์ด ์žˆ์–ด. ๋ฏธ๋ฆฌ ์•Œ์•„๋‘๋ฉด ์‹œ๊ฐ„์„ ๋งŽ์ด ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ์ง€!

โŒ ๋ฌธ์ œ 1: "GDI+ ์ผ๋ฐ˜ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค"

์›์ธ:
โ€ข ํŒŒ์ผ์ด ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค์—์„œ ์‚ฌ์šฉ ์ค‘
โ€ข ํŒŒ์ผ ๊ฒฝ๋กœ์— ์“ฐ๊ธฐ ๊ถŒํ•œ ์—†์Œ
โ€ข ์ด๋ฏธ์ง€ ํฌ๋งท์ด ์ง€์›๋˜์ง€ ์•Š์Œ
โ€ข ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•:

// ๋‚˜์œ ์˜ˆ
Bitmap img = new Bitmap("image.jpg");
img.Save("image.jpg"); // ๊ฐ™์€ ํŒŒ์ผ์— ์ €์žฅ ์‹œ๋„ - ์˜ค๋ฅ˜!

// ์ข‹์€ ์˜ˆ 1: ๋‹ค๋ฅธ ํŒŒ์ผ๋ช…์œผ๋กœ ์ €์žฅ
Bitmap img = new Bitmap("image.jpg");
img.Save("image_edited.jpg");
img.Dispose();

// ์ข‹์€ ์˜ˆ 2: ์ŠคํŠธ๋ฆผ ์‚ฌ์šฉ
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
    Bitmap img = new Bitmap(fs);
    // ์ž‘์—… ์ˆ˜ํ–‰
    img.Save("output.jpg");
    img.Dispose();
}

// ์ข‹์€ ์˜ˆ 3: ๋ณต์‚ฌ๋ณธ ๋งŒ๋“ค๊ธฐ
using (Image original = Image.FromFile("image.jpg"))
{
    Bitmap copy = new Bitmap(original);
    copy.Save("image.jpg"); // ์›๋ณธ ํŒŒ์ผ ๋ฎ์–ด์“ฐ๊ธฐ ๊ฐ€๋Šฅ
    copy.Dispose();
}


โŒ ๋ฌธ์ œ 2: ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜

์ฆ์ƒ:
โ€ข ํ”„๋กœ๊ทธ๋žจ์ด ์ ์  ๋А๋ ค์ง
โ€ข ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์ด ๊ณ„์† ์ฆ๊ฐ€
โ€ข OutOfMemoryException ๋ฐœ์ƒ

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•:

// ๋‚˜์œ ์˜ˆ
public void ProcessImages()
{
    for (int i = 0; i < 1000; i++)
    {
        Bitmap img = new Bitmap(1000, 1000);
        // Dispose ํ˜ธ์ถœ ์•ˆ ํ•จ!
    }
}

// ์ข‹์€ ์˜ˆ
public void ProcessImages()
{
    for (int i = 0; i < 1000; i++)
    {
        using (Bitmap img = new Bitmap(1000, 1000))
        {
            // ์ž‘์—… ์ˆ˜ํ–‰
        } // ์ž๋™์œผ๋กœ Dispose ํ˜ธ์ถœ
    }
}

// ๋” ์ข‹์€ ์˜ˆ: ๋ช…์‹œ์  GC ํ˜ธ์ถœ (๋Œ€๋Ÿ‰ ์ฒ˜๋ฆฌ ์‹œ)
public void ProcessManyImages()
{
    for (int i = 0; i < 1000; i++)
    {
        using (Bitmap img = new Bitmap(1000, 1000))
        {
            // ์ž‘์—… ์ˆ˜ํ–‰
        }
        
        // 100๊ฐœ๋งˆ๋‹ค ๊ฐ€๋น„์ง€ ์ปฌ๋ ‰์…˜
        if (i % 100 == 0)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
        }
    }
}


โŒ ๋ฌธ์ œ 3: ์ด๋ฏธ์ง€ ํ’ˆ์งˆ ์ €ํ•˜

์›์ธ:
โ€ข ์ž˜๋ชป๋œ InterpolationMode ์„ค์ •
โ€ข JPEG ์••์ถ• ํ’ˆ์งˆ์ด ๋„ˆ๋ฌด ๋‚ฎ์Œ
โ€ข ์—ฌ๋Ÿฌ ๋ฒˆ ์ €์žฅ/๋กœ๋“œ ๋ฐ˜๋ณต

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•:

// ๊ณ ํ’ˆ์งˆ ํฌ๊ธฐ ์กฐ์ ˆ
public Bitmap HighQualityResize(Image original, int width, int height)
{
    Bitmap resized = new Bitmap(width, height);
    
    using (Graphics g = Graphics.FromImage(resized))
    {
        // ์ตœ๊ณ  ํ’ˆ์งˆ ์„ค์ •
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        g.CompositingQuality = CompositingQuality.HighQuality;
        
        g.DrawImage(original, 0, 0, width, height);
    }
    
    return resized;
}

// ๊ณ ํ’ˆ์งˆ JPEG ์ €์žฅ
public void SaveHighQualityJpeg(Bitmap image, string path)
{
    ImageCodecInfo jpegCodec = ImageCodecInfo.GetImageEncoders()
        .First(c => c.MimeType == "image/jpeg");
    
    EncoderParameters encoderParams = new EncoderParameters(1);
    encoderParams.Param[0] = new EncoderParameter(
        System.Drawing.Imaging.Encoder.Quality, 95L); // 95% ํ’ˆ์งˆ
    
    image.Save(path, jpegCodec, encoderParams);
}


โŒ ๋ฌธ์ œ 4: ํˆฌ๋ช…๋„ ์ฒ˜๋ฆฌ ๋ฌธ์ œ

์ฆ์ƒ:
โ€ข PNG ํˆฌ๋ช… ๋ฐฐ๊ฒฝ์ด ๊ฒ€์€์ƒ‰์œผ๋กœ ๋ณ€ํ•จ
โ€ข ์•ŒํŒŒ ์ฑ„๋„์ด ์†์‹ค๋จ

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•:

// ํˆฌ๋ช…๋„๋ฅผ ์œ ์ง€ํ•˜๋ฉฐ ํฌ๊ธฐ ์กฐ์ ˆ
public Bitmap ResizeWithTransparency(Image original, int width, int height)
{
    // PixelFormat.Format32bppArgb ์‚ฌ์šฉ (์•ŒํŒŒ ์ฑ„๋„ ํฌํ•จ)
    Bitmap resized = new Bitmap(width, height, PixelFormat.Format32bppArgb);
    
    using (Graphics g = Graphics.FromImage(resized))
    {
        // ํˆฌ๋ช… ๋ฐฐ๊ฒฝ
        g.Clear(Color.Transparent);
        
        // CompositingMode ์„ค์ •
        g.CompositingMode = CompositingMode.SourceOver;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        
        g.DrawImage(original, 0, 0, width, height);
    }
    
    return resized;
}

// PNG๋กœ ์ €์žฅ (ํˆฌ๋ช…๋„ ์œ ์ง€)
resized.Save("output.png", ImageFormat.Png);


โŒ ๋ฌธ์ œ 5: ๋Œ€์šฉ๋Ÿ‰ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์‹œ ์„ฑ๋Šฅ ์ €ํ•˜

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•:

// 1. ์ด๋ฏธ์ง€๋ฅผ ์ž‘์€ ํƒ€์ผ๋กœ ๋‚˜๋ˆ„์–ด ์ฒ˜๋ฆฌ
public void ProcessLargeImageInTiles(Bitmap largeImage, int tileSize)
{
    int tilesX = (int)Math.Ceiling((double)largeImage.Width / tileSize);
    int tilesY = (int)Math.Ceiling((double)largeImage.Height / tileSize);
    
    Parallel.For(0, tilesX * tilesY, tileIndex =>
    {
        int tileX = tileIndex % tilesX;
        int tileY = tileIndex / tilesX;
        
        int x = tileX * tileSize;
        int y = tileY * tileSize;
        int w = Math.Min(tileSize, largeImage.Width - x);
        int h = Math.Min(tileSize, largeImage.Height - y);
        
        Rectangle tileRect = new Rectangle(x, y, w, h);
        
        // ํƒ€์ผ ์ฒ˜๋ฆฌ
        ProcessTile(largeImage, tileRect);
    });
}

// 2. ์ŠคํŠธ๋ฆฌ๋ฐ ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌ
public void ProcessImageStreaming(string inputPath, string outputPath)
{
    using (FileStream inputStream = new FileStream(inputPath, FileMode.Open))
    using (Image image = Image.FromStream(inputStream, false, false))
    {
        // ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋งŒ ์ฝ๊ณ  ํ•„์š”ํ•œ ๋ถ€๋ถ„๋งŒ ๋กœ๋“œ
        // ์ž‘์—… ์ˆ˜ํ–‰
        
        using (FileStream outputStream = new FileStream(outputPath, FileMode.Create))
        {
            image.Save(outputStream, ImageFormat.Jpeg);
        }
    }
}

๐Ÿ“š ์ถ”๊ฐ€ ํ•™์Šต ๋ฆฌ์†Œ์Šค์™€ ํŒ

์—ฌ๊ธฐ๊นŒ์ง€ ์™”๋‹ค๋ฉด ์ด๋ฏธ C# ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ์˜ ๊ธฐ์ดˆ๋Š” ๋งˆ์Šคํ„ฐํ•œ ๊ฑฐ์•ผ! ํ•˜์ง€๋งŒ ๋ฐฐ์›€์—๋Š” ๋์ด ์—†์ง€. ๋” ๊นŠ์ด ๊ณต๋ถ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด๋Ÿฐ ๊ฒƒ๋“ค์„ ์‚ดํŽด๋ณด๋ฉด ์ข‹์•„:

๐Ÿ“– ์ถ”์ฒœ ํ•™์Šต ์ฃผ์ œ

๊ณ ๊ธ‰ ํ•„ํ„ฐ๋ง ๐ŸŽจ
โ€ข ๊ฐ€์šฐ์‹œ์•ˆ ๋ธ”๋Ÿฌ
โ€ข ์—ฃ์ง€ ๊ฒ€์ถœ
โ€ข ๋ชจ์…˜ ๋ธ”๋Ÿฌ
โ€ข ๋…ธ์ด์ฆˆ ์ œ๊ฑฐ

์ด๋ฏธ์ง€ ๋ถ„์„ ๐Ÿ”
โ€ข ํžˆ์Šคํ† ๊ทธ๋žจ ๋ถ„์„
โ€ข ์ƒ‰์ƒ ๋ถ„ํฌ
โ€ข ๋ฐ๊ธฐ ๋ถ„์„
โ€ข ํŒจํ„ด ์ธ์‹

๊ณ ๊ธ‰ ๋ณ€ํ™˜ ๐Ÿ”„
โ€ข ์›๊ทผ ๋ณ€ํ™˜
โ€ข ์™œ๊ณก ๋ณด์ •
โ€ข ๋ชจํ•‘
โ€ข ํŒŒ๋…ธ๋ผ๋งˆ

์ตœ์ ํ™” ๊ธฐ๋ฒ• โšก
โ€ข SIMD ํ™œ์šฉ
โ€ข GPU ๊ฐ€์†
โ€ข ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ
โ€ข ์บ์‹ฑ ์ „๋žต


๐Ÿ’ก ์‹ค์ „ ํ”„๋กœ์ ํŠธ ์•„์ด๋””์–ด

1. ์‚ฌ์ง„ ํŽธ์ง‘ ์•ฑ ํ•„ํ„ฐ, ํฌ๋กญ, ํšŒ์ „, ํ…์ŠคํŠธ ์ถ”๊ฐ€ ๋“ฑ์˜ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง„ ์™„์ „ํ•œ ์‚ฌ์ง„ ํŽธ์ง‘ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

2. ๋ฐฐ์น˜ ์ด๋ฏธ์ง€ ํ”„๋กœ์„ธ์„œ
์—ฌ๋Ÿฌ ์ด๋ฏธ์ง€๋ฅผ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋Š” ๋„๊ตฌ (ํฌ๊ธฐ ์กฐ์ ˆ, ์›Œํ„ฐ๋งˆํฌ, ํฌ๋งท ๋ณ€ํ™˜)

3. ์Šคํฌ๋ฆฐ์ƒท ๋„๊ตฌ
ํ™”๋ฉด ์บก์ฒ˜, ์ฃผ์„ ์ถ”๊ฐ€, ์ž๋™ ์—…๋กœ๋“œ ๊ธฐ๋Šฅ

4. ์ด๋ฏธ์ง€ ๋น„๊ต ๋„๊ตฌ
๋‘ ์ด๋ฏธ์ง€์˜ ์ฐจ์ด์ ์„ ์ฐพ์•„๋‚ด๋Š” ํ”„๋กœ๊ทธ๋žจ

5. QR ์ฝ”๋“œ ์ƒ์„ฑ๊ธฐ
ํ…์ŠคํŠธ๋‚˜ URL์„ QR ์ฝ”๋“œ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜

6. ์ฝœ๋ผ์ฃผ ๋ฉ”์ด์ปค
์—ฌ๋Ÿฌ ์‚ฌ์ง„์„ ์กฐํ•ฉํ•ด์„œ ํ•˜๋‚˜์˜ ์ฝœ๋ผ์ฃผ ์ด๋ฏธ์ง€ ์ƒ์„ฑ

7. ์ด๋ฏธ์ง€ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ํŽธ์ง‘๊ธฐ
EXIF ์ •๋ณด ์ฝ๊ธฐ/์“ฐ๊ธฐ, GPS ์ •๋ณด ๊ด€๋ฆฌ

8. ์ž๋™ ๋ฆฌ์‚ฌ์ด์ง• ์„œ๋น„์Šค
์›น ์„œ๋ฒ„์—์„œ ์š”์ฒญ์— ๋”ฐ๋ผ ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ๋™์ ์œผ๋กœ ์กฐ์ ˆ


๐ŸŽฏ ์„ฑ๋Šฅ ๋ฒค์น˜๋งˆํ‚น ํŒ

using System.Diagnostics;

public class PerformanceTester
{
    public void BenchmarkImageOperation(Action operation, string operationName)
    {
        // ์›Œ๋ฐ์—… (JIT ์ปดํŒŒ์ผ)
        operation();
        
        // ์‹ค์ œ ์ธก์ •
        Stopwatch sw = Stopwatch.StartNew();
        operation();
        sw.Stop();
        
        Console.WriteLine($"{operationName}: {sw.ElapsedMilliseconds}ms");
    }
    
    public void ComparePerformance()
    {
        Bitmap testImage = new Bitmap(1920, 1080);
        
        // GetPixel/SetPixel vs LockBits ๋น„๊ต
        BenchmarkImageOperation(() => 
        {
            ConvertToGrayscaleGetPixel(testImage);
        }, "GetPixel/SetPixel");
        
        BenchmarkImageOperation(() => 
        {
            ConvertToGrayscaleLockBits(testImage);
        }, "LockBits");
        
        BenchmarkImageOperation(() => 
        {
            ConvertToGrayscaleParallel(testImage);
        }, "LockBits + Parallel");
        
        testImage.Dispose();
    }
}


๐Ÿ”ง ๋””๋ฒ„๊น… ํŒ

// ์ด๋ฏธ์ง€ ์ •๋ณด ์ถœ๋ ฅ ํ—ฌํผ
public void PrintImageInfo(Image image, string label = "Image")
{
    Console.WriteLine($"=== {label} ===");
    Console.WriteLine($"ํฌ๊ธฐ: {image.Width} x {image.Height}");
    Console.WriteLine($"ํ”ฝ์…€ ํฌ๋งท: {image.PixelFormat}");
    Console.WriteLine($"ํ•ด์ƒ๋„: {image.HorizontalResolution} x {image.VerticalResolution} DPI");
    Console.WriteLine($"์›๋ณธ ํฌ๋งท: {image.RawFormat}");
    Console.WriteLine($"ํ”„๋ ˆ์ž„ ์ˆ˜: {image.GetFrameCount(FrameDimension.Page)}");
    Console.WriteLine();
}

// ์ฒ˜๋ฆฌ ์ „ํ›„ ๋น„๊ต
public void CompareImages(Bitmap before, Bitmap after)
{
    Console.WriteLine("=== ์ด๋ฏธ์ง€ ๋น„๊ต ===");
    Console.WriteLine($"ํฌ๊ธฐ ๋ณ€ํ™”: {before.Width}x{before.Height} โ†’ {after.Width}x{after.Height}");
    
    // ํŒŒ์ผ ํฌ๊ธฐ ๋น„๊ต (๋ฉ”๋ชจ๋ฆฌ ์ŠคํŠธ๋ฆผ ์‚ฌ์šฉ)
    using (MemoryStream msBefore = new MemoryStream())
    using (MemoryStream msAfter = new MemoryStream())
    {
        before.Save(msBefore, ImageFormat.Png);
        after.Save(msAfter, ImageFormat.Png);
        
        Console.WriteLine($"๋ฉ”๋ชจ๋ฆฌ ํฌ๊ธฐ: {msBefore.Length / 1024}KB โ†’ {msAfter.Length / 1024}KB");
    }
}

๐ŸŽฌ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์™€! ์—ฌ๊ธฐ๊นŒ์ง€ ์ •๋ง ๊ธด ์—ฌ์ •์ด์—ˆ์–ด. C# System.Drawing์„ ํ™œ์šฉํ•œ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ์˜ ๊ฑฐ์˜ ๋ชจ๋“  ๊ฒƒ์„ ๋‹ค๋ค„๋ดค์–ด.

๐ŸŽ“ ์šฐ๋ฆฌ๊ฐ€ ๋ฐฐ์šด ๋‚ด์šฉ ์ •๋ฆฌ:

โœ… System.Drawing ๋„ค์ž„์ŠคํŽ˜์ด์Šค์˜ ๊ธฐ๋ณธ ๊ตฌ์กฐ์™€ ์ฃผ์š” ํด๋ž˜์Šค๋“ค
โœ… ์ด๋ฏธ์ง€ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ, ์ €์žฅํ•˜๊ธฐ, ํฌ๊ธฐ ์กฐ์ ˆํ•˜๊ธฐ
โœ… Graphics ํด๋ž˜์Šค๋กœ ๋„ํ˜•๊ณผ ํ…์ŠคํŠธ ๊ทธ๋ฆฌ๊ธฐ
โœ… ๋‹ค์–‘ํ•œ ์ด๋ฏธ์ง€ ํ•„ํ„ฐ์™€ ํšจ๊ณผ ์ ์šฉํ•˜๊ธฐ
โœ… ColorMatrix๋ฅผ ํ™œ์šฉํ•œ ์ƒ‰์ƒ ๋ณ€ํ™˜
โœ… ๊ณ ์„ฑ๋Šฅ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ๊ธฐ๋ฒ• (LockBits, ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ)
โœ… ์‹ค์ „ ํ”„๋กœ์ ํŠธ: ImageProcessor ํด๋ž˜์Šค ๊ตฌํ˜„
โœ… WinForms์™€์˜ ํ†ตํ•ฉ
โœ… ์„ฑ๋Šฅ ์ตœ์ ํ™” ๋ฐฉ๋ฒ•
โœ… ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์™€ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•
โœ… .NET Core/5+ ํ™˜๊ฒฝ์—์„œ์˜ ๋ณ€ํ™”์™€ ๋Œ€์•ˆ


๐Ÿ’ช ์ด์ œ ๋‹น์‹ ์€:

โ€ข ํ”„๋กœ๊ทธ๋ž˜๋ฐ์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ž์œ ์ž์žฌ๋กœ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ์–ด
โ€ข ์ž๋™ํ™”๋œ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์‹œ์Šคํ…œ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด
โ€ข ์„ฑ๋Šฅ์„ ๊ณ ๋ คํ•œ ํšจ์œจ์ ์ธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์–ด
โ€ข ์‹ค์ „ ํ”„๋กœ์ ํŠธ์— ๋ฐ”๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์‹ค๋ ฅ์„ ๊ฐ–์ท„์–ด

๐Ÿš€ ๋‹ค์Œ ๋‹จ๊ณ„:

์ด์ œ ๋ฐฐ์šด ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ์ž์‹ ๋งŒ์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ด. ์ž‘์€ ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ ์  ๋ณต์žกํ•œ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๊ฐ€๋ฉด์„œ ์‹ค๋ ฅ์„ ํ‚ค์›Œ๋‚˜๊ฐ€๋ฉด ๋ผ.

ํ˜น์‹œ ๋ง‰ํžˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด, ์ด ๊ธ€์„ ๋‹ค์‹œ ์ฐธ๊ณ ํ•˜๊ฑฐ๋‚˜ ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์•„. ๊ทธ๋ฆฌ๊ณ  ์ง์ ‘ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์‹คํ—˜ํ•ด๋ณด๋Š” ๊ฒŒ ๊ฐ€์žฅ ์ค‘์š”ํ•ด. ์ด๋ก ๋งŒ ์•„๋Š” ๊ฒƒ๊ณผ ์ง์ ‘ ํ•ด๋ณด๋Š” ๊ฒƒ์€ ์™„์ „ํžˆ ๋‹ค๋ฅด๊ฑฐ๋“ !

๐ŸŒŸ ๋งˆ์ง€๋ง‰์œผ๋กœ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ๋Š์ž„์—†๋Š” ํ•™์Šต์˜ ๊ณผ์ •์ด์•ผ. ์ƒˆ๋กœ์šด ๊ธฐ์ˆ ์ด ๊ณ„์† ๋‚˜์˜ค๊ณ , ๋” ๋‚˜์€ ๋ฐฉ๋ฒ•๋“ค์ด ๋ฐœ๊ฒฌ๋˜์ง€. ํ•˜์ง€๋งŒ ์—ฌ๊ธฐ์„œ ๋ฐฐ์šด ๊ธฐ์ดˆ ๊ฐœ๋…๋“ค์€ ์–ด๋–ค ํ™˜๊ฒฝ์—์„œ๋“  ์œ ์šฉํ•˜๊ฒŒ ์“ฐ์ผ ๊ฑฐ์•ผ.

ํ–‰์šด์„ ๋นŒ์–ด! ๋ฉ‹์ง„ ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ณด๊ธธ ๋ฐ”๋ž„๊ฒŒ! ๐ŸŽจโœจ

๐ŸŽฏ ์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?

C# ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ์— ๋Œ€ํ•ด ๋” ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ๋‹ค๋ฉด,
์–ธ์ œ๋“ ์ง€ ์งˆ๋ฌธํ•˜๊ณ  ํ•จ๊ป˜ ์„ฑ์žฅํ•ด์š”!

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.