winForm 으로 이미지 로딩하기

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Formusing OpenCvSharp;
using OpenCvSharp.Extensions;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            showImageUsingPictureBox();
            showImageUsingPictureBoxIpl();
        }

        private void showImageUsingPictureBoxIpl()
        {
            using (var iplImage = new Mat(@"c:\lena512.jpg", ImreadModes.AnyDepth | ImreadModes.AnyColor))
            {
                Cv2.Dilate(iplImage, iplImage, new Mat());

                var pictureBoxIpl = new OpenCvSharp.UserInterface.PictureBoxIpl
                {
                    ImageIpl = iplImage,
                    AutoSize = true
                };
                flowLayoutPanel1.Controls.Add(pictureBoxIpl);

                //How to redraw:
                //pictureBoxIpl.RefreshIplImage(iplImage);
            }
        }

        private void showImageUsingPictureBox()
        {
            Bitmap bitmap;
            using (var iplImage = new Mat(@"c:\lena512.jpg", ImreadModes.AnyDepth | ImreadModes.AnyColor))
            {
                bitmap = iplImage.ToBitmap(); // BitmapConverter.ToBitmap()
            }

            var pictureBox = new PictureBox
            {
                Image = bitmap,
                ClientSize = bitmap.Size
            };

            //How to redraw:
            //iplImage.ToBitmap(dst: (Bitmap)pictureBox.Image);

            flowLayoutPanel1.Controls.Add(pictureBox);
        }
    }
}

댓글

댓글 쓰기

이 블로그의 인기 게시물

Draw Circle on PictureBox when Button Click - Winform

2D FFT of Gray Image by AForge