Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何在vb中保存图片框(绘画程序)中的内容_Vb.net_Image_Save - Fatal编程技术网

Vb.net 如何在vb中保存图片框(绘画程序)中的内容

Vb.net 如何在vb中保存图片框(绘画程序)中的内容,vb.net,image,save,Vb.net,Image,Save,我正在用microsoft visual basic 2010创建一个basic paint程序,并使用一个图片框作为画布,我想知道如何将该图片框中的内容以jpeg、pdf或其他格式保存到您的计算机中。首先,您需要将其保存为.bmp,然后转换为所需格式 这应该行得通 Imports System.Drawing.Imaging Private Sub btnSavePictureBox1_Click(sender As System.Object, e As System.EventArgs)

我正在用microsoft visual basic 2010创建一个basic paint程序,并使用一个图片框作为画布,我想知道如何将该图片框中的内容以jpeg、pdf或其他格式保存到您的计算机中。首先,您需要将其保存为.bmp,然后转换为所需格式

这应该行得通

Imports System.Drawing.Imaging

Private Sub btnSavePictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles btnSavePictureBox1.Click
    Dim WhateverSavePath As String = "C:\WhateverSavePath\"
    Dim WhateverImageName As String = "WhateverImageName.png"
    Dim bm As Bitmap = New Bitmap(PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height)
    PictureBox1.DrawToBitmap(bm, PictureBox1.ClientRectangle)
    Try
        If My.Computer.FileSystem.FileExists(WhateverSavePath & WhateverImageName) Then
            Dim overwrite As Integer
            overwrite = MessageBox.Show("File exist." & vbCrLf & vbCrLf & WhateverSavePath & WhateverImageName & vbCrLf & vbCrLf & "Do you want to overwrite the existing file?", "Overwrite file?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If overwrite = vbYes Then
                FileIO.FileSystem.DeleteFile(WhateverSavePath & WhateverImageName)
                bm.Save(WhateverSavePath & WhateverImageName, ImageFormat.Png)
                MessageBox.Show("Image Saved" & vbCrLf & vbCrLf & WhateverSavePath & WhateverImageName, "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            ElseIf overwrite = vbNo Then
                Exit Sub
            End If

        Else
            bm.Save(WhateverSavePath & WhateverImageName, ImageFormat.Png)
            MessageBox.Show("Image Saved" & vbCrLf & vbCrLf & WhateverSavePath & WhateverImageName, "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
        bm.Dispose()
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

在按钮单击事件中使用SaveFileDialog

Dim SFD As New SaveFileDialog
SFD.Filter = "BMP Images|*.bmp|JPG Images|*.jpg|PNG Images|*.png|GIF Images|*.gif"

If SFD.ShowDialog() = DialogResult.OK Then
    PictureBox1.Image.Save(SaveFileDialog1.FileName)
End If

注意:1)如果他不希望文件名始终相同,该怎么办?2) 如果他想指定一个自定义路径怎么办?3) 对于
图像
也有一个
.Save
属性。将其制作成位图会浪费内存。1和2很容易理解。这只是一个例子。3我认为这是因为它是一个画布,需要将其转换为位图,然后保存。它们很容易成为一个
SaveFileDialog
:)