これは私のコードです:
Public Class Form1
Public TheImage As Image = PictureBox1.BackgroundImage
Public Function AppendBorder(ByVal original As Image, ByVal borderWidth As Integer) As Image
Dim borderColor As Color = Color.Red
Dim mypen As New Pen(borderColor, borderWidth * 2)
Dim newSize As Size = New Size(original.Width + borderWidth * 2, original.Height + borderWidth * 2)
Dim img As Bitmap = New Bitmap(newSize.Width, newSize.Height)
Dim g As Graphics = Graphics.FromImage(img)
' g.Clear(borderColor)
g.DrawImage(original, New Point(borderWidth, borderWidth))
g.DrawRectangle(mypen, 0, 0, newSize.Width, newSize.Height)
g.Dispose()
Return img
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OutputImage As Image = AppendBorder(TheImage, 2)
PictureBox1.BackgroundImage = OutputImage
End Sub
End Class
PictureBox1
デザイナーで追加した実際の背景画像が の中にあります。しかし、デバッグすると、次のエラー メッセージが表示されます。
InvalidOperationException が処理されませんでした
私は何を間違っていますか?