4

我已经能够将文件另存为 .jpeg,但无法加载图像,有人有建议吗?

    Private Sub Btnconfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnconfirm.Click

        MsgBox("A receipt will now be saved to your files", vbOKOnly, "Thank you for your purchase")

        SaveFileDialog1.ShowDialog()
        MsgBox("Thank you for choosing Tiny Theatre, have a nice day.", vbOKOnly, "Thank you")
        Me.Close()
    End Sub

    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
        Dim FileToSaveAs As String = SaveFileDialog1.FileName

        Dim objwriter As New System.IO.StreamWriter(FileToSaveAs)
        objwriter.Write(PictureBox1)
        objwriter.Close()
    End Sub
4

1 回答 1

8

没试过,但是这个可以吗?

Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
    Dim FileToSaveAs As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, SaveFileDialog1.FileName)
    PictureBox1.Image.Save(FileToSaveAs, System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub

如果需要设置编码器参数(如 jpeg 压缩),则需要重载 Save 方法。请参阅http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image.aspxhttp://msdn.microsoft.com/en-us/library/system.drawing.image .aspx

提供的代码将图片框控件以序列化形式保存到扩展名为 jpeg 的文件中。将 text.txt 文件重命名为 text.jpg 不会使其成为有效的 jpg 图像。这是一样的。

于 2013-05-10T19:25:00.923 回答