1

描画したグラフィックを画像として保存しようとすると、このエラーが発生しました。画像は正常に保存されますが、エラーが表示され、「FileNotFound」と表示されます

これはペイントメソッドです(フォームロード時、自動的にグラフィックを描画します)

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

わからないことが 2 つあります。1. エラーがクリック メソッドではなくペイント メソッドにあるのはなぜですか。2.それを修正する方法は?

私の悪い英語で申し訳ありませんが助けてください

ありがとう :)

4

0 に答える 0