将绘制的图形保存到图像(错误)

时间:2013-09-30 05:04:39

标签: vb.net

当我尝试将绘制的图形保存为图像时,我收到此错误。 图像已成功保存,但出现错误,并显示“FileNotFound”

这是paint方法(当表单加载时,自动绘制图形)

Private Sub Pictprev2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Pictprev2.Paint
    Dim a As String = amplop.noSer.Text
    Dim b As String = amplop.nmpsrt.Text
    Dim C As String = amplop.ComboCluster.Text
    Dim d As String = amplop.ComboTraining.Text
    Dim newImage As Image = Image.FromFile("Certificate Envelope Background - blank.jpg")
    Dim pfc As New PrivateFontCollection()
    pfc.AddFontFile("Amplop.ttf")
    Dim font1 As New Font(pfc.Families(0), 11, FontStyle.Regular)
    Dim font2 As New Font(pfc.Families(0), 18, FontStyle.Underline)
    Dim font3 As New Font(pfc.Families(0), 11, FontStyle.Regular)
    Dim format As New StringFormat
    format.Alignment = StringAlignment.Far
    e.Graphics.DrawString("No. " & a, font1, Brushes.Black, 688, 408, format)
    e.Graphics.DrawString(b, font2, Brushes.Black, 688, 423, format)
    e.Graphics.DrawString(C & " | " & d, font3, Brushes.Black, 688, 448, format)
End Sub

行中的错误 Dim newImage As Image = Image.FromFile("Certificate Envelope Background - blank.jpg")

点击方法就像这样

Private Sub SameAsImageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SameAsImageToolStripMenuItem.Click
    Dim a As String = amplop.noSer.Text
    Dim b As String = amplop.nmpsrt.Text
    Dim C As String = amplop.ComboCluster.Text
    Dim d As String = amplop.ComboTraining.Text
    Dim pfc As New PrivateFontCollection()
    pfc.AddFontFile("Amplop.ttf")
    Dim font1 As New Font(pfc.Families(0), 14, FontStyle.Regular)
    Dim font2 As New Font(pfc.Families(0), 25, FontStyle.Underline)
    Dim font3 As New Font(pfc.Families(0), 14, FontStyle.Regular)
    Dim format As New StringFormat
    format.Alignment = StringAlignment.Far
    Dim jpg As Bitmap = Image.FromFile("Certificate Envelope Background - blank.jpg")
    Dim g As Graphics = Graphics.FromImage(jpg)
    g.SmoothingMode = SmoothingMode.AntiAlias
    g.DrawString("No. " & a, font1, Brushes.Black, 688 * 5, 421 * 5, format)
    g.DrawString(b, font2, Brushes.Black, 688 * 5, 432 * 5, format)
    g.DrawString(C & " | " & d, font3, Brushes.Black, 688 * 5, 453 * 5, format)
    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
        Dim paths As String = System.IO.Path.GetFullPath(SaveFileDialog1.FileName)
        PictureBox1.Image = jpg
        PictureBox1.Image.Save(paths & ".jpg", Imaging.ImageFormat.Jpeg)
    End If
End Sub

有两件事我不知道,  1.为什么错误位于paint方法中而不是click方法中?  2.如何解决这个问题?

请帮忙 抱歉我的英文不好

谢谢:)

0 个答案:

没有答案