Thursday, June 26, 2008

Create Image by code ( vb.net)

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
''Dim objGraphics As Graphics = System.Drawing.Graphics.FromImage(objBitmap)
Dim objBitmap As New Bitmap(99, 99)

DivisionLogo1.Image = Division.NoImage()
' ''DivisionLogo1.BackColor = Color.White
End Sub


' Load for Noimage in Division image box..
Public Function NoImage() As Bitmap
Dim Text As String = " NoImage"
Dim FontColor As Color = Color.Blue
Dim BackColor As Color = Color.White
Dim FontName As String = "Times New Roman"
Dim FontSize As Integer = 10
Dim Height As Integer = 99
Dim Width As Integer = 99
Dim FileName As String = "MyImage"
Dim objBitmap As New Bitmap(Width, Height)
''Step 5. Create a Graphics object using this Bitmap object.
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
''Step 6. Create Color, Font, and PointF objects.
'Dim objColor As Color
Dim objFont As New Font(FontName, FontSize)
'Following PointF object defines where the text will be displayed in the
'specified area of the image
Dim objPoint As New PointF(5.0F, 5.0F)
''Step 7. Create two SolidBrush type objects.
Dim objBrushForeColor As New SolidBrush(FontColor)
Dim objBrushBackColor As New SolidBrush(BackColor)
''Step 8. Draw rectangle using Graphics object and fill it with BackColor.
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
''Step 9. Draw Text string on the specified rectangle using Graphics object.
objGraphics.DrawString(Text, objFont, objBrushForeColor, objPoint)
Return objBitmap
End Function

No comments: