Zoom and Skew an Image : Image Operation « 2D Graphics « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
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
VB.Net Tutorial » 2D Graphics » Image Operation 
15. 49. 11. Zoom and Skew an Image
Zoom and Skew an Image
 

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

public class ZoomImageAndSkew
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class


Public Class Form1
    Inherits System.Windows.Forms.Form
    Private curImage As Image
    Private imgHeight As Single
    Private imgWidth As Single
    Private menuItem12 As System.Windows.Forms.MenuItem
    Private curFileName As String

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

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

        'Add any initialization after the InitializeComponent() call

    End Sub

    '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

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

    '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.
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents OpenFileMenu As System.Windows.Forms.MenuItem
    Friend WithEvents Zoom25Menu As System.Windows.Forms.MenuItem
    Friend WithEvents Zoom50Menu As System.Windows.Forms.MenuItem
    Friend WithEvents Zoom100Menu As System.Windows.Forms.MenuItem
    Friend WithEvents Zoom200Menu As System.Windows.Forms.MenuItem
    Friend WithEvents Zoom500Menu As System.Windows.Forms.MenuItem
    Friend WithEvents Skewing25Menu As System.Windows.Forms.MenuItem
    Friend WithEvents Skewing50Menu As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.OpenFileMenu = New System.Windows.Forms.MenuItem
        Me.Zoom25Menu = New System.Windows.Forms.MenuItem
        Me.Zoom50Menu = New System.Windows.Forms.MenuItem
        Me.Zoom100Menu = New System.Windows.Forms.MenuItem
        Me.Zoom200Menu = New System.Windows.Forms.MenuItem
        Me.Zoom500Menu = New System.Windows.Forms.MenuItem
        Me.Skewing25Menu = New System.Windows.Forms.MenuItem
        Me.Skewing50Menu = New System.Windows.Forms.MenuItem
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.OpenFileMenu})
        Me.MenuItem1.Text = "File"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 1
        Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.Zoom25Menu, Me.Zoom50Menu, Me.Zoom100Menu, Me.Zoom200Menu, Me.Zoom500Menu})
        Me.MenuItem2.Text = "Zoom"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 2
        Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.Skewing25Menu, Me.Skewing50Menu})
        Me.MenuItem3.Text = "Skewing"
        '
        'OpenFileMenu
        '
        Me.OpenFileMenu.Index = 0
        Me.OpenFileMenu.Text = "Open File"
        '
        'Zoom25Menu
        '
        Me.Zoom25Menu.Index = 0
        Me.Zoom25Menu.Text = "25%"
        '
        'Zoom50Menu
        '
        Me.Zoom50Menu.Index = 1
        Me.Zoom50Menu.Text = "50%"
        '
        'Zoom100Menu
        '
        Me.Zoom100Menu.Index = 2
        Me.Zoom100Menu.Text = "100%"
        '
        'Zoom200Menu
        '
        Me.Zoom200Menu.Index = 3
        Me.Zoom200Menu.Text = "200%"
        '
        'Zoom500Menu
        '
        Me.Zoom500Menu.Index = 4
        Me.Zoom500Menu.Text = "500%"
        '
        'Skewing25Menu
        '
        Me.Skewing25Menu.Index = 0
        Me.Skewing25Menu.Text = "25%"
        '
        'Skewing50Menu
        '
        Me.Skewing50Menu.Index = 1
        Me.Skewing50Menu.Text = "50%"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(496378)
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.Text = "Scaling"

    End Sub

#End Region

    Private Sub OpenFileMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles OpenFileMenu.Click
            curImage = Image.FromFile("yourfile.jpg")
            imgHeight = curImage.Height
            imgWidth = curImage.Width
        Invalidate()
    End Sub

    Private Sub Zoom25Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Zoom25Menu.Click
        imgHeight = imgHeight * 25 100
        imgWidth = imgWidth * 25 100
        Invalidate()
    End Sub

    Private Sub Zoom50Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Zoom50Menu.Click
        imgHeight = imgHeight * 50 100
        imgWidth = imgWidth * 50 100
        Invalidate()
    End Sub

    Private Sub Zoom100Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Zoom100Menu.Click
        imgHeight = imgHeight
        imgWidth = imgWidth
        Invalidate()
    End Sub

    Private Sub Zoom200Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Zoom200Menu.Click
        imgHeight = imgHeight * 200 100
        imgWidth = imgWidth * 200 100
        Invalidate()
    End Sub

    Private Sub Zoom500Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Zoom500Menu.Click
        imgHeight = imgHeight * 500 100
        imgWidth = imgWidth * 500 100
        Invalidate()
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        If Not (curImage Is NothingThen
            e.Graphics.DrawImage(curImage, AutoScrollPosition.X, AutoScrollPosition.Y, imgWidth, imgHeight)
        End If

    End Sub

    Private Sub Skewing25Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Skewing25Menu.Click
        Dim As Graphics = Me.CreateGraphics()
        g.Clear(Me.BackColor)

        Dim pts As Point() {New Point(15020), New Point(2050), New Point(150300)}

        g.DrawImage(curImage, pts)
        g.Dispose()
    End Sub
End Class

        
15. 49. Image Operation
15. 49. 1. Rotate an Image
15. 49. 2. Mirror an Image
15. 49. 3. Move an image and paintMove an image and paint
15. 49. 4. Scale an imageScale an image
15. 49. 5. Scale image with different Graphics UnitsScale image with different Graphics Units
15. 49. 6. Skew imageSkew image
15. 49. 7. Make an image transparentMake an image transparent
15. 49. 8. Invert an ImageInvert an Image
15. 49. 9. Invert an Image unsafeInvert an Image unsafe
15. 49. 10. Zoom ImageZoom Image
15. 49. 11. Zoom and Skew an ImageZoom and Skew an Image
15. 49. 12. Skew an ImageSkew an Image
w___ww.j_av__a___2_s._c__om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.