我是VB.net的新手,但我必须为我们的项目做这件事。我做了一个非常简单的程序来调用我在vb.net中创建的matlab函数。这个程序很简单,它只能确定图片框中图像的宽度和高度。
这是我的matlab代码,使用.NET程序集编译它以导出.dll文件:
function [width, height, third] = imageInfo(input)
inImage = imread(input);
[width, height, third] = size(inImage);
end
这是我的程序的GUI:
这是我制作的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
运行程序时总是出错。我希望你能帮我这个。谢谢
答案 0 :(得分:0)
这部分:
result = myImageInfo.imageInfo(imagePath)
imagePath
需要成为完整的道路。您将其删除并添加逗号
imagePath = "'" & ofdSelectPicture.FileName & "'"
您可以尝试:
imagePath = ofdSelectPicture.SafeFileName