1

私はこのコードセグメントを持っています:

    Dim myStream As Stream = Nothing
    Dim openFileDialog1 As New OpenFileDialog()

    openFileDialog1.InitialDirectory = "C:\Users\Desktop\Sample Pictures"
    openFileDialog1.Filter = "Pictures|*.jpg|Text|*.txt"

    If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            myStream = openFileDialog1.OpenFile()
            If (myStream IsNot Nothing) Then

              ' Insert code to read the stream here.

            End If
        End Sub
    End Class

myStream内のファイルを宛先フォルダーにコピーする必要があります。どうすればそれを実装できるか考えていますか?

4

3 に答える 3

1

使用できます:

Image img = Image.FromStream(myStream);

また

Image img = Image.FromFile(path);

そして、保存する方法:

img.Save("new location");

[サンプルはC#です]

于 2012-07-29T14:37:24.870 に答える
1

myDestinationDirがファイルをコピーするパスであると仮定すると、

If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then 
    ' Extract the filename part from the full filename returned by openDialog.'
    Dim selectedFile As String = Path.GetFileName(openFileDialog1.FileName)
    ' Append to the destinationDir the filename extracted'
    Dim destFile As String = Path.Combine(myDestinationDir, selectedFile)
    ' Copy with overwrite (if overwrite is not desidered, use the overload with False as 3 arg'
    System.IO.File.Copy(openFileDialog1.FileName, destFile)
End Sub 

これにより、選択したファイルが宛先フォルダーにコピーされ、同じ名前の既存のファイルが上書きされます。

于 2012-07-29T16:42:03.033 に答える
0

これは、実験用ソフトウェア用に作成した実際のコードの抜粋です。

    Dim strPath As String
    Dim fStream As FileStream
    Dim fileName As String

    Try
   '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Get path from textbox
    strPath = txtSavePath.Text.ToLower

    'Check directory existence, if not, create it
    If Directory.Exists(strPath) Then

    Else
        Try
            Directory.CreateDirectory(strPath)
        Catch ex As Exception

            MessageBox.Show("Error in Creating Directory, Code : " & ex.ToString)
        End Try

    End If

    'Set current active directory
    Directory.SetCurrentDirectory(strPath)

    'Create Filename
    fileName = txtFileName.Text.ToUpper & "_" & DateTime.Now.ToString("yyyyMMdd_HH_mm_ss")


    'Write/Create file
    fStream = File.Open(fileName & ".png", FileMode.Create)
    fStream.Write(byteData, 0, nLength)
    fStream.Close()
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Display On Window
        picGraphDisplay.BackgroundImage = Image.FromFile(fileName & ".png")
        txtSavedFileName.Text = fileName & ".png"
    Catch ex As Exception
        CheckVisaStatus(errorStatus)
        MessageBox.Show(ex.ToString)

    End Try

この場合、ファイルストリームは画像のバイトデータをファイルに書き込んでいます。バイト画像をどこから取得するかはあなた次第です。この場合、システムのを使用してここで行う、ファイルに特定の名前を使用することもお勧めしますDateTime.Now

それがあなたにいくつかのアイデアを与えたことを願っています。乾杯

于 2012-07-30T16:22:28.093 に答える