PictureBox を IplImage に合わせて伸縮させる例
300, 300 の Form1 いっぱいに PictureBox1 を置き,そこに表示する例.表示する画像に合わせて,Form1 を変形する.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using KwsmLab.OpenCvSharp; namespace OpenCvSharpTest { public partial class Form1 : Form { private IplImage img = new IplImage(@"C:\Data\Image\lena.png"); public Form1() { InitializeComponent(); pictureBox1.Image = img.ToBitmap(); if (img.Height - this.pictureBox1.Height != 0) { this.Height = this.Height + img.Height - this.pictureBox1.Height; } if (img.Width - this.pictureBox1.Width != 0) { this.Width = this.Width + img.Width - this.pictureBox1.Width; } } } }