0

以下は、ビデオを再生するために使用するコードです。ビデオはパネルで再生されますが、ビデオを開始すると、ビデオの一部しか表示されません。パネル内にビデオを収めるにはどうすればよいですか? また、アスペクト比を維持できるように、ビデオのデフォルト サイズ (高さと幅) を取得するにはどうすればよいですか。

Private Sub movieWindow_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles movieWindow.DragDrop
    Dim file_names As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
    Dim result As String
    For Each file_name As String In file_names
        result = file_name.Substring(file_name.LastIndexOf("\") + 1)
        frmPlayList.playlist.Items.Add(result)
        frmPlayList.playlist2.Items.Add(file_name)
    Next file_name

    frmPlayList.playlist2.SelectedIndex = frmPlayList.playlist2.Items.Count - 1
    filename = frmPlayList.playlist2.SelectedIndex
    retVal = mciSendString("play movie", 0, 0, 0)
End Sub
4

1 に答える 1

1

ビデオをホストしているパネルでムービーのサイズを自動的に変更するには、このコードを試してください。また、正しい縦横比を維持します。(パネルの名前を「movieWindow」に置き換えてください)

maxSize は、ビデオの最大サイズです。このサイズに収まるように強制されます。

「動画再生」コマンドを発行する直前に、サブルーチンを呼び出します。(2012 年 3 月 20 日編集 - 変数名のタイプミスを修正)。

SizeVideoWindow(movieWindow.size)
dim retval as integer = mcisendstring("play movie", 0, 0, 0)

Private Sub SizeVideoWindow(maxSize as size)

    Dim ActualMovieSize As Size = getDefaultSize()
    Dim AspectRatio As Single = ActualMovieSize.Width / ActualMovieSize.Height

    Dim iLeft As Integer = 0
    Dim iTop As Integer = 0

    Dim newWidth As Integer = maxSize.width
    Dim newHeight As Integer = newWidth \ AspectRatio

    If newHeight > maxSize.height Then

        newHeight = maxSize.height
        newWidth = newHeight * AspectRatio
        iLeft = (maxSize.width - newWidth) \ 2

    Else

        iTop = (maxSize.height - newHeight) \ 2

    End If

    mciSendString("put movie window at " & iLeft & " " & iTop & " " & newWidth & " " & newHeight, 0, 0, 0)

End Sub

Public Function getDefaultSize() As Size
    'Returns the default width, height the movie
    Dim c_Data As String = Space(128)
    mciSendString("where movie source", c_Data, 128, 0)
    Dim parts() As String = Split(c_Data, " ")

    Return New Size(CInt(parts(2)), CInt(parts(3)))
End Function
于 2012-03-16T04:00:10.410 に答える