Draw the text on image

1. I want to ask how can I draw the text on image.

2. Also the code below I don's know how to call the drawlinePoint in Page_load , anyone can help me. I write this but has error that I call the function, how can I call DrawLinPoint It is the Window Application.NET

Private Sub drawPoint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

DrawLinePoint(e)

End Sub

Public Sub DrawLinePoint(e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create points that define line.
Dim point1 As New Point(100, 100)
Dim point2 As New Point(500, 100)
' Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2)
End Sub




Answer this question

Draw the text on image

  • iam_RAms

    For the first question there is already several articles available describing how to do this. I recommend searching the Internet for it. It is too much code to go through here. However the bulk of it requires that you get a Graphics object from the bitmap. Use the returned Graphics object to draw the text. The text should then appear on the image. I might be missing a step.

    Graphics gfx = Graphics.FromImage(img);
    gfx.DrawString(...);

    For the second question the parameters are wrong. The Load event accepts an EventArgs parameter. The DrawLinePoint method requires a PaintEventArgs. You'll need to create a PaintEventArgs instance and pass it to the method (but this isn't trivial). However you shouldn't do any drawing in Load anyway. The problem is that Load is called after the controls are created but before they are displayed. Therefore anything you draw is going to get wiped out when the form/control paints itself. You should move the call to DrawLinePoint to inside the form's/control's OnPaint method. This ensures that it'll get drawn whenever the form/control does. It also gives you the PaintEventArgs argument that you need.

    Michael Taylor - 3/30/06


  • Data Base

    Hi,

    How do i do with GDI text (TextOut or DrawText)


  • Draw the text on image