1

当我尝试将绘制的图形另存为图像时出现此错误。图像保存成功,但出现错误,并说“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.如何解决?

请帮助对不起我的英语不好

谢谢 :)

4

0 回答 0