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

时间:2015-02-25 19:44:54

标签: vb.net image save

我正在使用microsoft visual basic 2010创建一个基本的绘图程序,我正在使用一个图片框作为我的画布,我想知道如何将该图片框中的内容保存到您的计算机中,如jpeg,pdf或其他< / p>

3 个答案:

答案 0 :(得分:0)

首先,您需要将其另存为.bmp,然后转换为所需的格式。

答案 1 :(得分:0)

在按钮点击事件中使用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

答案 2 :(得分:-1)

这应该有用......

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