이미지 로드
이미지 파일 경로를 통해 이미지를 로드합니다.
1 2 3 4 5 6 7 8 9
   | using System.Drawing.Imaging;
  public Bitmap LoadImage(string path) {     using (Bitmap bitmap = new Bitmap(path))     {         return bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format32bppArgb);     } }
   | 
 
 BitmapSource 변환
주어진 비트맵을 WPF 이미징 프레임워크에서 사용 가능한 BitmapSource 형식으로 변환합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   | using System.Drawing.Imaging; using System.Windows; using System.Windows.Media.Imaging;
  public BitmapSource ConvertGDIBitmapToWPF(Bitmap image) {     if (image == null)         return null;
      Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);     BitmapData bitmapData = image.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
      try     {         int size = rect.Width * rect.Height * 4;         BitmapSource result = BitmapSource.Create(image.Width, image.Height,             image.HorizontalResolution, image.VerticalResolution, PixelFormats.Bgra32,             null, bitmapData.Scan0, size, bitmapData.Stride);         result.Freeze();         return result;     }     finally     {         image.UnlockBits(bitmapData);     } }
   | 
 
 빈 비트맵 생성
주어진 크기를 갖는 빈 비트맵을 생성합니다.
1 2 3 4 5 6
   | using System.Drawing.Imaging;
  public Bitmap MakeEmptyImage(int width, int height) {     return new Bitmap(width, height, PixelFormat.Format32bppArgb); }
   |