Working with Image in Windows Application

Posted by Chikul under Windows Forms category on | Views : 1595
'Working with Image in Windows Application

Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging

Public Class frmDrawImg

Private Sub frmDrawImg_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim grpx As Graphics = e.Graphics
grpx.DrawImage(New Bitmap("SampleImage.png"), ClientRectangle)
End Sub

Public Sub New()

' This call is required by the Windows Form Designer.

' Add any initialization after the InitializeComponent() call.
' Create a Bitmap Object
Dim bmp As Bitmap = New Bitmap(800, 600, PixelFormat.Format32bppArgb)

'Create a Graphics object using FromImage method
Dim grpx As Graphics = Graphics.FromImage(bmp)

'Call the Fill Rectangle method
'to create an outer rectangle
grpx.FillRectangle(New SolidBrush(Color.BlueViolet), New Rectangle(0, 0, 800, 600))

'Create Font and RectangleF object
Dim fntText As Font = New Font("Verdana", 20)
Dim rect As RectangleF = New RectangleF(100, 100, 250, 300)

'Fill the InnerRectangle
'Add the text to the Inner Rectangle
grpx.FillRectangle(New SolidBrush(Color.Chocolate), rect)
grpx.DrawString("WEL COME", fntText, New SolidBrush(Color.LawnGreen), rect)

'Draw a Closed Curve
Dim penBlack As Pen = New Pen(Color.Black, 20)
penBlack.DashStyle = DashStyle.Dash
penBlack.StartCap = LineCap.Round
penBlack.EndCap = LineCap.Round

grpx.DrawClosedCurve(penBlack, New Point() { _
New Point(50, 100), _
New Point(400, 100), _
New Point(350, 400), _
New Point(50, 400)})

'Save the newly Created image file
bmp.Save("SampleImage.png", ImageFormat.Png)

End Sub
End Class

Comments or Responses

Login to post response