Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Dim bm_src As Bitmap = picSource.Image.Clone
Dim bm_out As New Bitmap(bm_src.Width, bm_src.Height)
Dim gr As Graphics = Graphics.FromImage(bm_out)
' Give the image an alpha gradient.
Dim alpha As Integer
For x As Integer = 0 To bm_src.Width - 1
alpha = (255 * x) \ bm_src.Width
For y As Integer = 0 To bm_src.Height - 1
Dim clr As Color = bm_src.GetPixel(x, y)
clr = Color.FromArgb(alpha, clr.R, clr.G, clr.B)
bm_src.SetPixel(x, y, clr)
Next y
Next x
' Draw the image onto the result.
gr.DrawImage(bm_src, 0, 0)
' Draw some text on the result.
Dim layout_rect As New RectangleF(0, 0, bm_src.Width, _
bm_src.Height)
Dim string_format As New StringFormat
string_format.LineAlignment = StringAlignment.Far
string_format.Alignment = StringAlignment.Center
Dim the_brush As New SolidBrush(Me.ForeColor)
gr.DrawString("Smile!", Me.Font, the_brush, _
layout_rect, string_format)
the_brush.Dispose()
' Display the result.
picResult.Image = bm_out
End Sub
|