⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xipmain.vb

📁 这个是国外大学的项目代码
💻 VB
📖 第 1 页 / 共 5 页
字号:
        End If
        Dim bmp As Drawing.Bitmap
        bmp = Drawing.Bitmap.FromFile(dlgOpenImage.FileName)
        If IsNothing(bmp) Then
            Exit Sub
        End If
        If CheckDataSize(bmp, , lstImage.SelectedIndex) Then
            MsgBox("Image not added." & Chr(13) & Chr(10) & "Data size would exceede memory capacity.", MsgBoxStyle.Information)
            Exit Sub
        End If
        IMGCOLL.Remove(lstImage.SelectedIndex + 1)
        IMGCOLL.Add(bmp, Nothing, lstImage.SelectedIndex + 1)
        lstImage.Items.Item(lstImage.SelectedIndex) = dlgOpenImage.FileName
        DataChanged()
    End Sub

    Private Sub btnImageSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImageSave.Click
        If lstImage.SelectedIndex = -1 Then
            Exit Sub
        End If
        Dim bmp As Drawing.Bitmap
        bmp = IMGCOLL.Item(lstImage.SelectedIndex + 1)
        If dlgSaveImage.ShowDialog() = DialogResult.Cancel Then
            Exit Sub
        End If
        Dim frmt As Drawing.Imaging.ImageFormat
        Select Case dlgSaveImage.FilterIndex()
            Case 1 : frmt = Drawing.Imaging.ImageFormat.Bmp
            Case 2 : frmt = Drawing.Imaging.ImageFormat.Jpeg
            Case 3 : frmt = Drawing.Imaging.ImageFormat.Gif
            Case 4 : frmt = Drawing.Imaging.ImageFormat.Png
            Case 5 : frmt = Drawing.Imaging.ImageFormat.Tiff
        End Select

        If Not dlgSaveImage.FileName.EndsWith(imagefilter(dlgSaveImage.FilterIndex - 1)) Then
            dlgSaveImage.FileName += imagefilter(dlgSaveImage.FilterIndex - 1)
        End If
        bmp.Save(dlgSaveImage.FileName, frmt)
        'TODO
    End Sub

    Private Sub lstImage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstImage.SelectedIndexChanged
        If lstImage.SelectedIndex <> -1 Then
            Dim bmp As Drawing.Bitmap
            Dim zoom As Double = 1.0
            bmp = IMGCOLL.Item(lstImage.SelectedIndex + 1)
            If bmp.Width > pcbPicture.Width Then
                zoom = pcbPicture.Width / bmp.Width
            End If
            If bmp.Height * zoom > pcbPicture.Height Then
                zoom = pcbPicture.Height / bmp.Height
            End If
            pcbPicture.Image = bmp.GetThumbnailImage(bmp.Width * zoom, bmp.Height * zoom, Nothing, IntPtr.Zero)
            grpPicture.Text = "Picture: " & bmp.Width() & " x " & bmp.Height
            If fpgauptodate And hif <> 0 Then
                DisplayImage()
            End If
        Else
            pcbPicture.Image = Nothing
        End If
    End Sub

    Private Sub lstImage_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstImage.DoubleClick
        If fpgauptodate Or DataChanged() Then
            fpgauptodate = True
            DisplayImage()
        Else
            MsgBox("Data must be synchronized!", MsgBoxStyle.Information)
        End If
    End Sub

    Private Sub btnProcessNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcessNew.Click
        If lstProcess.Items.Count >= 6 Then
            MsgBox("No more porcesses allowed!", MsgBoxStyle.Information)
            Exit Sub
        End If
        If frmImageProcess.ShowDialog(Me) = DialogResult.Cancel Then
            Exit Sub
        End If
        Dim pr As New PRC
        pr.src = frmImageProcess.cboSource.Text
        If frmImageProcess.cboDestination.SelectedIndex = 0 Then
            pr.dest = "Image " & IMGCOLL.Count
            IMGCOLL.Add(IMGCOLL.Item(lstImage.Items.IndexOf(pr.src) + 1).clone)
            lstImage.Items.Add(pr.dest)
        Else
            pr.dest = frmImageProcess.cboDestination.Text
        End If
        lstProcess.Items.Add(pr.src & " -> " & pr.dest)
        pr.alg = frmImageProcess.ValidateKernel()
        PRCCOLL.Add(pr)
        fpgauptodate = False
    End Sub

    Private Sub btnProcessDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcessDelete.Click
        If lstProcess.SelectedIndex = -1 Then
            Exit Sub
        End If
        PRCCOLL.Remove(lstProcess.SelectedIndex + 1)
        lstProcess.Items.RemoveAt(lstProcess.SelectedIndex)
        fpgauptodate = False
    End Sub

    Private Sub btnProcessClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcessClear.Click
        lstProcess.Items.Clear()
        For tmp As Integer = 1 To PRCCOLL.Count
            PRCCOLL.Remove(1)
        Next
        fpgauptodate = False
    End Sub

    Private Sub btnProcessModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcessModify.Click
        If lstProcess.SelectedIndex < 0 Then
            Exit Sub
        End If
        Dim pr As New PRC
        pr = PRCCOLL.Item(lstProcess.SelectedIndex + 1)
        frmImageProcess.cboSource.SelectedItem = pr.src
        frmImageProcess.cboDestination.SelectedItem = pr.dest
        frmImageProcess.SetKernel(pr.alg)
        If frmImageProcess.ShowDialog(Me) = DialogResult.Cancel Then
            Exit Sub
        End If
        pr.src = frmImageProcess.cboSource.Text
        If frmImageProcess.cboDestination.SelectedIndex = 0 Then
            pr.dest = "Image " & IMGCOLL.Count
            IMGCOLL.Add(IMGCOLL.Item(lstImage.Items.IndexOf(pr.src) + 1).clone)
            lstImage.Items.Add(pr.dest)
        Else
            pr.dest = frmImageProcess.cboDestination.Text
        End If
        pr.alg = frmImageProcess.ValidateKernel()

        lstProcess.Items.Item(lstProcess.SelectedIndex) = pr.src & " -> " & pr.dest
        PRCCOLL.Remove(lstProcess.SelectedIndex + 1)
        PRCCOLL.Add(pr, Nothing, lstProcess.SelectedIndex + 1)
        fpgauptodate = False
    End Sub

    Private Sub lstProcess_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstProcess.DoubleClick
        If lstProcess.Items.Count = 0 Then
            Exit Sub
        End If
        If Not fpgauptodate Then
            DataChanged()
        End If
        If fpgauptodate Then
            PerformProcess()
            If chkSynchronize.Checked Then
                tmrProcess.Start()
                tmrProcess.Enabled = True
                Me.Enabled = False
            End If
        Else
            MsgBox("Data must be synchronized first!", MsgBoxStyle.Information)
        End If
    End Sub

    Private Sub tmrProcess_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrProcess.Tick
        tmrProcess.Enabled = False
        DataImport()
        Me.Enabled = True
    End Sub

    Private Sub btnDataExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataExport.Click
        'If lstImage.Items.Count = 0 Then
        'LogN("Please give me something to do")
        'Exit Sub
        'End If
        DataChanged(True)
    End Sub

    Private Sub btnDataImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataImport.Click
        DataImport()
    End Sub

    Private Sub btnDataLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataLoad.Click
        If dlgOpenData.ShowDialog() = DialogResult.Cancel Then
            Exit Sub
        End If
        If Not LoadData(dlgOpenData.FileName) Then
            MsgBox("Failed to load file", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        DecodeData()
        fpgauptodate = False
    End Sub

    Private Sub btnDataStore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataStore.Click
        If lstImage.Items.Count = 0 Then
            Exit Sub
        End If
        If dlgSaveData.ShowDialog() = DialogResult.Cancel Then
            Exit Sub
        End If
        EncodeData()
        If Not dlgSaveData.FileName.EndsWith(".xip") Then
            dlgSaveData.FileName += ".xip"
        End If
        SaveData(dlgSaveData.FileName)
        LogN("")
    End Sub

    Private Sub btnLogClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogClear.Click
        txtLog.Clear()
    End Sub

    Private Sub txtLog_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLog.TextChanged
        txtLog.SelectionStart = txtLog.Text.Length
        txtLog.ScrollToCaret()
    End Sub

    Private Function DataChanged(Optional ByVal update As Boolean = False) As Boolean
        If Not (chkSynchronize.Checked Or update) Then
            fpgauptodate = False
            Exit Function
        End If
        If hif = 0 Then
            MsgBox("Data transfer interface not opened.")
            Exit Function
        End If
        EncodeData()
        If Not SendData() Then
            MsgBox("Failed to send data." & Chr(13) & Chr(10) & _
                "FPGA may not been programmed ?", MsgBoxStyle.Question)
            Exit Function
        End If
        SynchronizePWM()
        fpgauptodate = True
        DataChanged = True
    End Function

    Private Sub DataImport()
        If hif = 0 Then
            MsgBox("Data transfer interface not opened", MsgBoxStyle.Exclamation, "Failed to ")
            Exit Sub
        End If
        If Not GetData() Then
            MsgBox("Unable to recive data" & Chr(13) & Chr(10) & _
                "FPGA may not been programmed ?", MsgBoxStyle.Question)
            Exit Sub
        End If
        SynchronizePWM()
        DecodeData()
        fpgauptodate = True
    End Sub

    Private Sub btnDevStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDevStart.Click
        CloseInterface()
        OpenInterface()
    End Sub

    Private Sub btnDevStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDevStop.Click
        CloseInterface()
    End Sub

    Private Sub cboPWM_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        SynchronizePWM()
    End Sub

    Private Sub cboHorizontalDelay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboHorizontalDelay.SelectedIndexChanged
        SynchronizePWM()
    End Sub

    Private Sub cboVerticalDelay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboVerticalDelay.SelectedIndexChanged
        SynchronizePWM()
    End Sub

    Private Sub btnSendPWM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendPWM.Click
        SynchronizePWM()
    End Sub

    Private Sub btnSynchronized_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSynchronized.Click
        cboHorizontalDelay.SelectedIndex = 0
        cboVerticalDelay.SelectedIndex = 0
    End Sub

    Private Sub btnBestLook80ns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBestLook80ns.Click
        cboPWM.SelectedIndex = 0
        cboHorizontalDelay.SelectedIndex = 2
        cboVerticalDelay.SelectedIndex = 2
    End Sub

    Private Sub btnBestLook160ns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBestLook160ns.Click
        cboPWM.SelectedIndex = 4
        cboHorizontalDelay.SelectedIndex = 3
        cboVerticalDelay.SelectedIndex = 4
    End Sub

    Private Sub DisplayImage()
        If lstImage.SelectedI

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -