在vb.net中使用MATLAB函数

时间:2014-01-23 12:50:45

标签: vb.net matlab matlab-deployment matlab-compiler

我是VB.net的新手,但我必须为我们的项目做这件事。我做了一个非常简单的程序来调用我在vb.net中创建的matlab函数。这个程序很简单,它只能确定图片框中图像的宽度和高度。

这是我的matlab代码,使用.NET程序集编译它以导出.dll文件:

function [width, height, third] = imageInfo(input)
inImage = imread(input);
[width, height, third] = size(inImage);
end

这是我的程序的GUI:

enter image description here

这是我制作的vb代码:

Imports MathWorks.MATLAB.NET.Arrays
Imports MathWorks.MATLAB.NET.Utility
Imports imageInfo

Public Class Form1
    Public myImageInfo As New imageInfoClass

    Dim imageWidth As String
    Dim imageHeight As String
    Dim result As New MWNumericArray
    Dim imagePath As String

    Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
        If ofdSelectPicture.ShowDialog = DialogResult.OK Then
            pbImage.Image = Image.FromFile(ofdSelectPicture.FileName)
            imagePath = "'" & ofdSelectPicture.FileName & "'"
        End If
    End Sub

    Private Sub btnProcess_Click(sender As Object, e As EventArgs) Handles btnProcess.Click
        result = myImageInfo.imageInfo(imagePath)
        tbHeight.Text = imageHeight
        tbWidth.Text = imageWidth
    End Sub
End Class

运行程序时总是出错。我希望你能帮我这个。谢谢

1 个答案:

答案 0 :(得分:0)

这部分:

result = myImageInfo.imageInfo(imagePath)

imagePath需要成为完整的道路。您将其删除并添加逗号

imagePath = "'" & ofdSelectPicture.FileName & "'"

您可以尝试:

imagePath = ofdSelectPicture.SafeFileName