using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ImageCS2
{
public partial class Form1 : Form
{
[DllImport("ImageCPP.dll")]
public static extern IntPtr run1(string a, out int width, out int height, out int step);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string filename;
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
filename = op.FileName;
int width, height, step;
IntPtr dst = run1(filename, out width, out height, out step);
Bitmap img = new Bitmap(width, height, step, System.Drawing.Imaging.PixelFormat. Format24bppRgb, dst);
pictureBox1.Image = img;
}
}
}
}
(6) C++传递灰度图,在C#中的代码略有差别,代码如下:
[DllImport("raildetection.dll")]
public static extern IntPtr run1(string a , out int width, out int height, out int step);
private void button1_Click(object sender, EventArgs e)
{
string filename;
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
filename = op.FileName;
int width, height, step;
IntPtr dst = run1(filename,out width,out height, out step);
Bitmap img = new Bitmap(width, height, step, <strong>System.Drawing.Imaging.PixelFormat.Format8bppIndexed</strong>,dst);
<strong>img.Palette = CvToolbox.GrayscalePalette;</strong>
pictureBox1.Image = img;
}
}
public static class CvToolbox
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-63301-2.html
这次的回归感觉都是超棒
不干涉
看得也太透彻