예제 #1
0
 // 이미지 불러오는 콜백
 private void LoadImageBtn_Click(object sender, RoutedEventArgs e)
 {
     Microsoft.Win32.OpenFileDialog d = new Microsoft.Win32.OpenFileDialog
     {
         Filter = "Bitmap Image Files (*.bmp)|*.bmp"
     };
     if ((bool)d.ShowDialog())
     {
         System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(d.FileName);
         if (bmp.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
         {
             MessageBox.Show("It support only Format8bppIndexed.");
         }
         else
         {
             //현재 이미지에 넣고,
             m_CurrentBitmap = bmp;
             var data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);
             //화면에 출력
             OriginSource = BitmapSource.Create(data.Width, data.Height, bmp.HorizontalResolution, bmp.VerticalResolution, PixelFormats.Gray8, null, data.Scan0, data.Stride * data.Height, data.Stride);
             OriginSource.Freeze();
             bmp.UnlockBits(data);
             //기존 입력이미지는 비우고
             if (m_Tool.InputImage != null)
             {
                 m_Tool.InputImage.Dispose();
             }
             //현재 이미지를 입력이미지로
             m_Tool.InputImage = m_CurrentBitmap;
         }
     }
     //메세지 업데이트
     this.RaisePropertyChanged(nameof(Overlay));
     this.RaisePropertyChanged(nameof(Message));
 }
예제 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog d = new Microsoft.Win32.OpenFileDialog
            {
                Filter = "Bitmap Image Files (*.bmp)|*.bmp"
            };
            if ((bool)d.ShowDialog())
            {
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(d.FileName);
                if (bmp.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
                {
                }
                else
                {
                    m_CurrentBitmap = bmp;
                    var data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);

                    OriginSource = BitmapSource.Create(data.Width, data.Height, bmp.HorizontalResolution, bmp.VerticalResolution, PixelFormats.Gray8, null, data.Scan0, data.Stride * data.Height, data.Stride);
                    OriginSource.Freeze();
                    bmp.UnlockBits(data);
                }

                uc.Visibility = Visibility.Visible;
            }
        }