c# 读取图像 传入 c++dll 函数中

c++

extern "C" __declspec(dllexport)int main1(long Pointer, long Width, long Height)
{
    Hobject  ImageC;
    HTuple  WindowHandle;
    Hlong sr_Width,sr_Height;
    sr_Width=Width;
    sr_Height=Height;
    gen_image1(&ImageC,"byte", Width, Height, Pointer);
    set_window_attr("background_color","black");
   open_window(0,0,Width/2,Height/2,0,"","",&WindowHandle);
   HDevWindowStack::Push(WindowHandle);
   if (HDevWindowStack::IsOpen())
   {
        set_part(WindowHandle, 0, 0, sr_Height-1, sr_Width-1); // 显示部分
        disp_obj(ImageC, HDevWindowStack::GetActive());
   }
   return 0;
}

c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
//using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;

namespace qtlibvstest
{
    public partial class Form1 : Form
    {
         [DllImport("qtdll.dll")]
          public static extern int main1(long Pointer, long Width, long Height);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HObject ho_Image;
            HTuple Pointer, Width, Height,Type;
            HOperatorSet.ReadImage(out ho_Image, "d:/2016-18#b30.bmp");
            HOperatorSet.GetImagePointer1(ho_Image, out Pointer, out Type, out Width, out Height);
            main1(Pointer.L, Width.L, Height.L);
        }
    }
}

使用 GetImagePointer1 获得halcon图像所有的信息  包括 图像数据首地址指针,图像长 宽。 将指针和图像大小用long型传入c++函数。

发布了8 篇原创文章 · 获赞 0 · 访问量 425

猜你喜欢

转载自blog.csdn.net/youandme520/article/details/103096315