2014-10-18 46 views
1

即時圖片試圖將圖片從PictureBox移動到另一個,該圖片被網絡攝像頭捕獲,但我的代碼無法正常工作。將圖像從圖片框移動到另一個圖片的另一個圖片盒

Public Class Form12 
Private _capture As Emgu.CV.Capture 
Private _captureInProgress As Boolean 
Dim form23 As Form23 

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 
    form23.SetPictureBoxImage(captureImageBox.Image) 
    form23.Show() 
End Sub 

Private Sub captureButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles captureButton.Click 
     If (_capture Is Nothing) Then 
      Try 
       _capture = New Emgu.CV.Capture 
      Catch excpt As NullReferenceException 
       MessageBox.Show(excpt.Message) 
      End Try 
     End If 
     If (Not _capture Is Nothing) Then 
      If _captureInProgress Then 
       Me.captureButton.Text = "Start Capture" 
       RemoveHandler Application.Idle, New EventHandler(AddressOf Me.ProcessFrame) 

      Else 
       captureButton.Text = "Capture" 
       AddHandler Application.Idle, New EventHandler(AddressOf Me.ProcessFrame) 
      End If 
      _captureInProgress = Not _captureInProgress 
     End If 
End Sub 

Private Sub ProcessFrame(ByVal sender As Object, ByVal arg As EventArgs) 

    Dim frame As Emgu.CV.Image(Of Emgu.CV.Structure.Bgr, Byte) = Me._capture.QueryFrame 
    Dim grayFrame As Emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) = frame.Convert(Of Emgu.CV.Structure.Gray, Byte)() 
    Dim smoothedGrayFrame As Emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) = grayFrame.PyrDown.PyrUp 

    captureImageBox.Image = frame.Bitmap 
End Sub 

Private Sub ReleaseData() 
    If (Not _capture Is Nothing) Then 
     _capture.Dispose() 
    End If 
End Sub 

第二表格

Public Class Form23 
Public Sub SetPictureBoxImage(ByVal image As Bitmap) 
    PictureBox1.Image = image 
End Sub 
End Class 

所有攝像頭的事情是工作,只是圖像的傳輸是沒有的。對不起,這裏只是一個新手。剛剛從教程中獲得這些代碼。謝謝!

+0

對於開始,我沒有看到form23的實例;也VB不區分大小寫,所以'Dim form23作爲Form23'不是一個好主意。如果不能提供描述性名稱,請使用'frm23'。因爲,它看起來像你正在設置類,而不是形式,屬性。更改爲'Dim frm23作爲新的Form23'並修復引用到'frm23'並且它應該工作 – Plutonix 2014-10-18 19:57:52

+0

它仍然沒有複製/轉移到另一個'PictureBox1'我的代碼還有什麼問題?hmm – 2014-10-18 20:06:16

+0

哇!就這麼簡單,你再次拯救了我的未來! :) 謝謝你,先生! :) – 2014-10-18 20:15:57

回答

1

形式是類 - 它是這麼說的,在所有這些的頂部:

Public Class Form817 

所以,他們的實例應該創建並且那是你的代碼應該在任何地方使用什麼:

Dim myFrm As Form817   ' DECLARES the variable 
myFrm = New Form817    ' Initialize myFrm as an instance of Form817 

' short method: 
Dim myFrm As New Form817 

的問題是在這裏:

form23.SetPictureBoxImage(captureImageBox.Image) 
form23.Show() 

VB不區分大小寫的,你的代碼沒有創造和實例,所以第一行是引用類,而不是實例。當你通常做類似Form23.Show - 而沒有創建一個實例時,VB爲你創建一個同名的實例。這被稱爲默認表單實例,應該避免(總是)。

您的圖像傳輸失敗,因爲代碼引用了一個事件(Form23),但顯示了另一個事件(Form23的一個新實例)。

+0

哦,這就是它是如何,我也在ASP.NET中使用這些東西?謝謝! – 2014-10-18 20:24:09

相關問題