一、picturebox显示图像
public partial class ucCamera : UserControl
{
public ucCamera()
{
InitializeComponent();
}
private delegate void DelegateMethod(string file);
public void ShowImg(string file)
{
DelegateMethod method = new DelegateMethod(Show);
pictureBox1.Invoke(method,file);
}
private void Show(string file)
{
if (File.Exists(file))
{
pictureBox1.Load(file);
}
}
}
private void btnShowImg_Click(object sender, EventArgs e)
{
ucCamera1.ShowImg(@"C:\Users\shang\Desktop\詹姆斯.jpg");
}
一、打开图像
private void bnOpenImg_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string filename = dlg.FileName;
ucCamera1.ShowImg(filename);
ucHalconWindow1.ShowImg(filename);
}
}
以下为ucHalconWindow代码,ucCamera代码在上面
public void ShowImg(string filename)
{
HTuple width, height;
HObject ho_Image, ho_GrayImage;
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_GrayImage);
ho_Image.Dispose();
HOperatorSet.ReadImage(out ho_Image, filename);
ho_GrayImage.Dispose();
HOperatorSet.GetImageSize(ho_Image, out width, out height);
HOperatorSet.SetPart(hwin, 0, 0, height - 1, width - 1);
HOperatorSet.DispObj(ho_Image, hwin);
}