使用OpenFileDialog上传图像,并将图像从其原始位置移动/剪切到另一个位置

时间:2016-08-18 06:07:18

标签: vb.net

请帮忙。我怎样才能使用vb.net将图像传输到另一个位置?

我已经尝试过这种策略,但它没有用。

Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
    If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
        fullPath = dlg.FileName 'c:\Sample\image1.jpg
        ImageFileName = Path.GetFileName(dlg.FileName) 'image1.jpg filename holder
        PathHolder = Path.Combine("d:\FinalLocation", ImageFileName)
        With PictureBox2
            .Image = Image.FromFile(fullPath )
            .SizeMode = PictureBoxSizeMode.Zoom
        End With
    End If
End Sub

然后当用户点击保存按钮时,我有一个像这样的代码

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    File.Move(fullPath, PathHolder) 'the 1st try
    'System.IO.File.Move(fullPath, PathHolder) '2nd try but its not working at all
End Sub

提前致谢:)

1 个答案:

答案 0 :(得分:1)

这很容易。您的代码是正确的,但保存按钮中缺少1行。

尝试添加:

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
picturebox2.image.dispose()
File.Move(fullPath, PathHolder)
End Sub

我认为您无法将图像移动到其他位置,因为图片框仍在使用它。

试一试:)