.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Working with Image in Windows Application

Posted By:Prasanti Prusty       Posted Date: February 28, 2010    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Working with Image in Windows Application
 

 

'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()
        MyBase.New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' 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

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend