๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš€ Development/C#

[C#] GDI+ (Graphics Device Interface Plus) ๋ž€?

by Jay Din 2024. 11. 19.
728x90
๋ฐ˜์‘ํ˜•

GDI+๋ž€?

GDI+ (Graphics Device Interface Plus) Microsoft๊ฐ€ Windows์—์„œ ๊ทธ๋ž˜ํ”ฝ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์ œ๊ณตํ•˜๋Š” API์ž…๋‹ˆ๋‹ค.

  • GDI๋Š” ๊ธฐ์กด์˜ GDI(Graphics Device Interface)๋ฅผ ํ™•์žฅํ•œ ๋ฒ„์ „์œผ๋กœ, ๊ทธ๋ž˜ํ”ฝ, ํ…์ŠคํŠธ, ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ๋ฅด ์œ„ํ•œ ๋” ๋งŽ์€ ๊ธฐ๋Šฅ๊ณผ ํ–ฅ์ƒ๋œ ์„ฑ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • .NET Framework์—์„œ System.Drawing ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

1. GDI+์˜ ์ฃผ์š” ๊ธฐ๋Šฅ

GDI+๋Š” 2D ๊ทธ๋ž˜ํ”ฝ ๋ Œ๋”๋ง๊ณผ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๋„๋ก ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  1. ๊ทธ๋ž˜ํ”ฝ
    • ์„ , ์‚ฌ๊ฐํ˜•, ์›๊ณผ ๊ฐ™์€ 2D ๋„ํ˜•์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์ƒ‰์ƒ, ์„  ๋‘๊ป˜, ์Šคํƒ€์ผ ๋“ฑ์„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. ํ…์ŠคํŠธ
    • ํฐํŠธ ์Šคํƒ€์ผ, ํฌ๊ธฐ, ์ปฌ๋Ÿฌ๋ฅผ ์ง€์ •ํ•˜์—ฌ ํ…์ŠคํŠธ๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๊ฐœ๋ณ„ ๊ธ€์ž์˜ ์œ„์น˜๋ฅผ ์ œ์–ดํ•˜๊ฑฐ๋‚˜ ํ…์ŠคํŠธ๋ฅผ ๊ธฐ์šธ์ด๋Š” ๋“ฑ์˜ ๊ณ ๊ธ‰ ํ…์ŠคํŠธ ์กฐ์ž‘ ๊ฐ€๋Šฅ.
  3. ์ด๋ฏธ์ง€
    • ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋กœ๋“œํ•˜๊ณ  ๋ณ€ํ™˜, ํšŒ์ „, ์ž๋ฅด๊ธฐ ๋“ฑ์˜ ์กฐ์ž‘์„ ์ˆ˜ํ–‰.
    • PNG, JPEG, BMP, GIF ๋“ฑ ๋‹ค์–‘ํ•œ ์ด๋ฏธ์ง€ ํ˜•์‹์„ ์ง€์›.
  4. ํˆฌ๋ช…๋„์™€ ์•ˆํ‹ฐ์•จ๋ฆฌ์–ด์‹ฑ
    • ํˆฌ๋ช…๋„: ๋ฐ˜ํˆฌ๋ช… ํšจ๊ณผ๋ฅผ ํ† ํ•ด ๊ทธ๋ž˜ํ”ฝ์˜ ๋ ˆ์ด์–ด๋ฅผ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ‘œํ˜„.
    • ์•ˆํ‹ฐ์•จ๋ฆฌ์–ด์‹ฑ: ๊ทธ๋ž˜ํ”ฝ์„ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๋ Œ๋”๋งํ•˜์—ฌ ๊ฒฝ๊ณ„์„ ์ด ๊ฑฐ์น ๊ฒŒ ๋ณด์ด์ง€ ์•Š๋„๋ก ์ฒ˜๋ฆฌ.
  5. ๊ณ ๊ธ‰ ๊ทธ๋ž˜ํ”ฝ ์ž‘์—…
    • ๊ฒฝ๋กœ(Path)๋ฅผ ์‚ฌ์šฉํ•œ ๋ณต์žกํ•œ ๋„ํ˜• ์ƒ์„ฑ.
    • ๋ณ€ํ™”(ํšŒ์ „, ํฌ๊ธฐ ์กฐ์ •, ์ด๋™)๊ณผ ๊ฐ™์€ 2D ๊ทธ๋ž˜ํ”ฝ ๋ณ€ํ™˜.
    • ๋น„ํŠธ๋งต ๋ฐ์ดํ„ฐ ์ง์ ‘ ์กฐ์ž‘

 

2. GDI+ ๊ตฌ์„ฑ ์š”์†Œ

(1). Graphics ํด๋ž˜์Šค

  • GDI+์˜ ํ•ต์‹ฌ ํด๋ž˜์Šค ํ™”๋ฉด, ์ด๋ฏธ์ง€, ํ”„๋ฆฐํ„ฐ์™€ ๊ฐ™์€ ๊ทธ๋ž˜ํ”ฝ ์ถœ๋ ฅ ์žฅ์น˜์™€ ์ƒํ˜ธ ์ž‘์šฉ.
  • System.Drawing.Graphics๋ฅผ ํ†ตํ•ด ์ œ๊ณต๋˜๋ฉฐ, ์ฃผ๋กœ Paint ์ด๋ฒคํŠธ๋‚˜ ์ด๋ฏธ์ง€๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ฐ ์‚ฌ์šฉ.

์˜ˆ์ œ: ๊ฐ„๋‹จํ•œ ์„  ๊ทธ๋ฆฌ๊ธฐ

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

public class MainForm : Form
{
    protected override void OnPaint(PaintEventArgs e)
    {
        Graphics g = e.Graphics;

        // ๋นจ๊ฐ„์ƒ‰ ์„  ๊ทธ๋ฆฌ๊ธฐ
        Pen pen = new Pen(Color.Red, 2);
        g.DrawLine(pen, 10, 10, 100, 100);

        pen.Dispose();
        base.OnPaint(e);
    }
}

public static class Program
{
    public static void Main()
    {
        Application.Run(new MainForm());
    }
}

 

(2). Pen ํด๋ž˜์Šค

  • ์„ ์˜ ์ƒ‰์ƒ, ๋‘๊ป˜, ์Šคํƒ€์ผ ๋“ฑ์„ ์ •์˜.
  • Pen ๊ฐ์ฒด๋Š” ์ง์„ , ๊ณก์„ , ๊ฒฝ๊ณ„์„  ๋“ฑ์„ ๊ทธ๋ฆฌ๋Š” ๋ฐ ์‚ฌ์šฉ.

์˜ˆ์ œ: Pen ์Šคํƒ€์ผ ์„ค์ •

Pen dashedPen = new Pen(Color.Blue, 2);
dashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

 

(3). Brush ํด๋ž˜์Šค

  • ๋„ํ˜• ๋‚ด๋ถ€๋ฅผ ์ฑ„์šฐ๋Š” ๋ฐ ์‚ฌ์šฉ.
  • ๋‹จ์ƒ‰ ๋ธŒ๋Ÿฌ์‹œ, ๊ทธ๋ผ๋ฐ์ด์…˜ ๋ธŒ๋Ÿฌ์‹œ ๋“ฑ ๋‹ค์–‘ํ•œ ์ข…๋ฅ˜ ์ œ๊ณต.

์˜ˆ์ œ: ์‚ฌ๊ฐํ˜• ๋‚ด๋ถ€ ์ฑ„์šฐ๊ธฐ

Brush solidBrush = new SolidBrush(Color.Green);
g.FillRectangle(solidBrush, 20, 20, 80, 80);
 
 

(4). Bitmap ํด๋ž˜์Šค

  • ์ด๋ฏธ์ง€ ์ž‘์—…์„ ์œ„ํ•œ ํด๋ž˜์Šค.
  • ์ด๋ฏธ์ง€๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œํ•˜๊ณ , ๋ณ€ํ˜•ํ•˜๊ฑฐ๋‚˜ ์ €์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ.

์˜ˆ์ œ: ์ด๋ฏธ์ง€ ๋กœ๋“œ ๋ฐ ํšŒ์ „

Bitmap bitmap = new Bitmap("image.jpg");
bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
bitmap.Save("rotated_image.jpg");
 
 

(5). Path ๋ฐ Region

  • GraphicsPath: ๊ณก์„ , ๋„ํ˜•, ํ…์ŠคํŠธ ๋“ฑ์„ ๊ฒฝ๋กœ ํ˜•ํƒœ๋กœ ์ •์˜.
  • Region: ๋„ํ˜• ์˜์—ญ์„ ์ •์˜ํ•˜๊ณ  ๋ณต์žกํ•œ ํด๋ฆฌํ•‘ ์ž‘์—… ์ˆ˜ํ–‰.

 

3. GDI+ ์‚ฌ์šฉ์˜ ์žฅ์ 

  1. ์‰ฌ์šด ์‚ฌ์šฉ:
    • .NET ํ™˜๊ฒฝ์—์„œ System.Drawing ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์‰ฝ๊ฒŒ ์ ‘๊ทผ ๊ฐ€๋Šฅ.
  2. ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ:
    • 2D ๊ทธ๋ž˜ํ”ฝ, ์ด๋ฏธ์ง€, ํ…์ŠคํŠธ ๋ Œ๋”๋ง ๋“ฑ ๋‹ค์–‘ํ•œ ์ž‘์—… ์ง€์›.
  3. ์šด์˜์ฒด์ œ ํ†ตํ•ฉ:
    • Windows ์šด์˜์ฒด์ œ์— ํ†ตํ•ฉ๋˜์–ด ์žˆ์–ด ๋น ๋ฅธ ์„ฑ๋Šฅ์„ ์ œ๊ณต.

 

4. GDI+ ์‚ฌ์šฉ ์‹œ ์ฃผ์˜ํ•  ์ 

  1. ์„ฑ๋Šฅ ์ œํ•œ:
    • GDI+๋Š” ๊ณ ์„ฑ๋Šฅ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜(์˜ˆ: ๊ฒŒ์ž„)์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Œ.
    • ์‹ค์‹œ๊ฐ„ 3D ๊ทธ๋ž˜ํ”ฝ ์ž‘์—…์€ OpenGL, DirectX ๊ฐ™์€ ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•จ.
  2. ์ž์› ๊ด€๋ฆฌ:
    • GDI+ ๊ฐ์ฒด(Graphics, Bitmap, Pen, Brush)๋Š” ๋น„๊ด€๋ฆฌ ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉ.
    • ์ž‘์—…์ด ๋๋‚œ ํ›„ ๋ฐ˜๋“œ์‹œ Dispose ํ˜ธ์ถœํ•˜์—ฌ ์ž์› ํ•ด์ œ.
  3. ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋”ฉ:
    • GDI+๋Š” ์Šค๋ ˆ๋“œ ์„ธ์ดํ”„ํ•˜์ง€ ์•Š์Œ. UI ์ž‘์—…์€ ๋ฐ˜๋“œ์‹œ UI ์Šค๋ ˆ๋“œ์—์„œ ์‹คํ–‰ํ•ด์•ผ ํ•จ.

 

5. GDI+์™€ WPF ๋น„๊ต

ํŠน์ง• GDI+ WPF
์ถœ์‹œ ์‹œ๊ธฐ .NET Framework ์ดˆ๊ธฐ (2002) .NET Framework 3.0 (2006)
์„ฑ๋Šฅ CPU ๊ธฐ๋ฐ˜ GPU ๊ฐ€์† ์ง€์›
์ง€์› ๊ธฐ๋Šฅ ๊ธฐ๋ณธ 2D ๊ทธ๋ž˜ํ”ฝ 2D/3D ๊ทธ๋ž˜ํ”ฝ, ์• ๋‹ˆ๋ฉ”์ด์…˜
์‚ฌ์šฉ ๋‚œ์ด๋„ ๋น„๊ต์  ์‰ฌ์›€ ๋” ๋†’์€ ํ•™์Šต ๊ณก์„ 
์ ํ•ฉ์„ฑ ๊ฐ„๋‹จํ•œ ๊ทธ๋ž˜ํ”ฝ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ณ ๊ธ‰ UI์™€ ๋ณต์žกํ•œ ๊ทธ๋ž˜ํ”ฝ

 

 

728x90
๋ฐ˜์‘ํ˜•