Displaying and resizing an image : Draw Image « 2D « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
VB.Net » 2D » Draw ImageScreenshots 
Displaying and resizing an image
Displaying and resizing an image

Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Drawing.Text

Public Class MainClass

   Shared Sub Main()
        Dim myform As Form = New FrmDisplayLogo()
        Application.Run(myform)
   End Sub ' Main

End Class




Public Class FrmDisplayLogo
   Inherits System.Windows.Forms.Form

   ' width controls
   Friend WithEvents txtWidth As TextBox
   Friend WithEvents lblWidth As Label

   ' height controls
   Friend WithEvents lblHeight As Label
   Friend WithEvents txtHeight As TextBox

   Private mGraphicsObject As Graphics
   Private mImage As Image

   ' sets member variables on form load
   Private Sub FrmDisplayLogo_Load(ByVal sender As _
      System.Object, ByVal e As System.EventArgs_
      Handles MyBase.Load

      ' get Form's graphics object
      mGraphicsObject = Me.CreateGraphics

      ' load image
      mImage = Image.FromFile("figure2.bmp")

   End Sub ' FrmDisplayLogo_Load

#Region " Windows Form Designer generated code "

   Public Sub New()
      MyBase.New()

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

      ' Add any initialization after InitializeComponent() call
   End Sub ' new

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is NothingThen
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents cmdSetButton As System.Windows.Forms.Button

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.Container

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
      Me.lblWidth = New System.Windows.Forms.Label()
      Me.lblHeight = New System.Windows.Forms.Label()
      Me.txtWidth = New System.Windows.Forms.TextBox()
      Me.txtHeight = New System.Windows.Forms.TextBox()
      Me.cmdSetButton = New System.Windows.Forms.Button()
      Me.SuspendLayout()
      '
      'lblWidth
      '
      Me.lblWidth.Location = New System.Drawing.Point(44056)
      Me.lblWidth.Name = "lblWidth"
      Me.lblWidth.TabIndex = 0
      Me.lblWidth.Text = "Width"
      '
      'lblHeight
      '
      Me.lblHeight.Location = New System.Drawing.Point(440128)
      Me.lblHeight.Name = "lblHeight"
      Me.lblHeight.TabIndex = 2
      Me.lblHeight.Text = "Height"
      '
      'txtWidth
      '
      Me.txtWidth.Location = New System.Drawing.Point(44088)
      Me.txtWidth.Name = "txtWidth"
      Me.txtWidth.TabIndex = 1
      Me.txtWidth.Text = ""
      '
      'txtHeight
      '
      Me.txtHeight.Location = New System.Drawing.Point(440160)
      Me.txtHeight.Name = "txtHeight"
      Me.txtHeight.TabIndex = 3
      Me.txtHeight.Text = ""
      '
      'cmdSetButton
      '
      Me.cmdSetButton.Location = New System.Drawing.Point(456200)
      Me.cmdSetButton.Name = "cmdSetButton"
      Me.cmdSetButton.TabIndex = 4
      Me.cmdSetButton.Text = "Set"
      '
      'FrmDisplayLogo
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(513)
      Me.ClientSize = New System.Drawing.Size(568273)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdSetButton, Me.txtHeight, Me.lblHeight, Me.txtWidth, Me.lblWidth})
      Me.Name = "FrmDisplayLogo"
      Me.Text = "Display Logo"
      Me.ResumeLayout(False)

   End Sub

#End Region

   Private Sub cmdSetButton_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgsHandles cmdSetButton.Click


      Dim width As Integer = Convert.ToInt32(txtWidth.Text)
      Dim height As Integer = Convert.ToInt32(txtHeight.Text)


      If (width > 375 OrElse height > 225Then
         MessageBox.Show("Height or Width too large")

         Return
      End If
      mGraphicsObject.Clear(Me.BackColor


      mGraphicsObject.DrawImage(mImage, 55, width, height)
   End Sub 

End Class 
           
       
Related examples in the same category
1. Process an Image: invert PixelProcess an Image: invert Pixel
2. Draw Image on a FrameDraw Image on a Frame
w__w__w_._j_a__v_a2s__.c___om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.