VB.Net Tutorial/2D Graphics/Image Operation — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:54, 26 мая 2010

Invert an Image

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Math
public class RevertImage
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim bm As New Bitmap("yourfile.jpg")
        e.Graphics.DrawImage(bm, 0, 0, 400, 400)
        Dim dest_bm As New Bitmap("yourfile.jpg")
        InvertImage(dest_bm)
        
        e.Graphics.DrawImage(dest_bm, 400, 0, 400, 400)
  End Sub
    Private Sub InvertImage(ByVal bm As Bitmap)
        For y As Integer = 0 To bm.Height - 1
            For x As Integer = 0 To bm.Width - 1
                Dim clr As Color = bm.GetPixel(x, y)
                clr = Color.FromArgb(255,255 - clr.R, 255 - clr.G, 255 - clr.B)
                bm.SetPixel(x, y, clr)
            Next x
        Next y
    End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class

Invert an Image unsafe

"Visual Basic 2005 Programmer"s Reference
"by Rod Stephens (Author) 
"# Publisher: Wrox (October 21, 2005)
"# Language: English
"# ISBN-10: 0764571982
"# ISBN-13: 978-0764571985
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Math
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
public class InvertImageUnsafe
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class BitmapBytesRGB24
    " Provide public access to the picture"s byte data.
    Public ImageBytes() As Byte
    Public RowSizeBytes As Integer
    Public Const PixelDataSize As Integer = 24
    " A reference to the Bitmap.
    Private m_Bitmap As Bitmap
    " Save a reference to the bitmap.
    Public Sub New(ByVal bm As Bitmap)
        m_Bitmap = bm
    End Sub
    " Bitmap data.
    Private m_BitmapData As BitmapData
    " Lock the bitmap"s data.
    Public Sub LockBitmap()
        " Lock the bitmap data.
        Dim bounds As Rectangle = New Rectangle( _
            0, 0, m_Bitmap.Width, m_Bitmap.Height)
        m_BitmapData = m_Bitmap.LockBits(bounds, _
            Imaging.ImageLockMode.ReadWrite, _
            Imaging.PixelFormat.Format24bppRgb)
        RowSizeBytes = m_BitmapData.Stride
        " Allocate room for the data.
        Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
        ReDim ImageBytes(total_size)
        " Copy the data into the ImageBytes array.
        Marshal.Copy(m_BitmapData.Scan0, ImageBytes, _
            0, total_size)
    End Sub
    " Copy the data back into the Bitmap
    " and release resources.
    Public Sub UnlockBitmap()
        " Copy the data back into the bitmap.
        Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
        Marshal.Copy(ImageBytes, 0, _
            m_BitmapData.Scan0, total_size)
        " Unlock the bitmap.
        m_Bitmap.UnlockBits(m_BitmapData)
        " Release resources.
        ImageBytes = Nothing
        m_BitmapData = Nothing
    End Sub
End Class
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
            Dim bm As New Bitmap("yourfile.jpg")
            Dim source_bm As New Bitmap(bm)
            bm.Dispose()
            picSource.Image = source_bm
            " Arrange the controls.
            picDest.Size = picSource.Size
            " Make the result Bitmap.
            Dim dest_bm As New Bitmap(source_bm)
            " Invert the image"s pixels.
            Dim start_time As DateTime
            Dim stop_time As DateTime
            Dim elapsed_time As TimeSpan
            start_time = Now
            InvertImage(dest_bm)
            stop_time = Now
            " Display the results.
            picDest.Image = dest_bm
            elapsed_time = stop_time.Subtract(start_time)
            MessageBox.Show(elapsed_time.TotalSeconds.ToString("0.0000") & " seconds")
    End Sub
    " Invert the pixel values in this Bitmap. 
    Private Sub InvertImage(ByVal bm As Bitmap)
        " Make a BitmapBytesRGB24 object.
        Dim bm_bytes As New BitmapBytesRGB24(bm)
        " Lock the bitmap.
        bm_bytes.LockBitmap()
        Dim pix As Integer
        For y As Integer = 0 To bm.Height - 1
            pix = y * bm_bytes.RowSizeBytes
            For x As Integer = 0 To bm.Width - 1
                " Blue component.
                bm_bytes.ImageBytes(pix) = CByte(255) - bm_bytes.ImageBytes(pix)
                pix += 1
                " Green component.
                bm_bytes.ImageBytes(pix) = CByte(255) - bm_bytes.ImageBytes(pix)
                pix += 1
                " Red component.
                bm_bytes.ImageBytes(pix) = CByte(255) - bm_bytes.ImageBytes(pix)
                pix += 1
            Next x
        Next y
        " Unlock the bitmap.
        bm_bytes.UnlockBitmap()
    End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SplitContainer1 = New System.Windows.Forms.SplitContainer
        Me.picSource = New System.Windows.Forms.PictureBox
        Me.picDest = New System.Windows.Forms.PictureBox
        Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
        Me.mnuFile = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuFileOpen = New System.Windows.Forms.ToolStripMenuItem
        Me.dlgOpenImage = New System.Windows.Forms.OpenFileDialog
        Me.SplitContainer1.Panel1.SuspendLayout()
        Me.SplitContainer1.Panel2.SuspendLayout()
        Me.SplitContainer1.SuspendLayout()
        CType(Me.picSource, System.ruponentModel.ISupportInitialize).BeginInit()
        CType(Me.picDest, System.ruponentModel.ISupportInitialize).BeginInit()
        Me.MenuStrip1.SuspendLayout()
        Me.SuspendLayout()
        "
        "SplitContainer1
        "
        Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.SplitContainer1.Location = New System.Drawing.Point(0, 24)
        Me.SplitContainer1.Name = "SplitContainer1"
        "
        "SplitContainer1.Panel1
        "
        Me.SplitContainer1.Panel1.AutoScroll = True
        Me.SplitContainer1.Panel1.Controls.Add(Me.picSource)
        "
        "SplitContainer1.Panel2
        "
        Me.SplitContainer1.Panel2.AutoScroll = True
        Me.SplitContainer1.Panel2.Controls.Add(Me.picDest)
        Me.SplitContainer1.Size = New System.Drawing.Size(522, 249)
        Me.SplitContainer1.SplitterDistance = 270
        Me.SplitContainer1.TabIndex = 3
        Me.SplitContainer1.Text = "SplitContainer1"
        "
        "picSource
        "
        Me.picSource.AutoSize = True
        Me.picSource.Location = New System.Drawing.Point(0, 0)
        Me.picSource.Name = "picSource"
        Me.picSource.Size = New System.Drawing.Size(208, 184)
        Me.picSource.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.picSource.TabIndex = 0
        Me.picSource.TabStop = False
        "
        "picDest
        "
        Me.picDest.AutoSize = True
        Me.picDest.Location = New System.Drawing.Point(0, 0)
        Me.picDest.Name = "picDest"
        Me.picDest.Size = New System.Drawing.Size(184, 184)
        Me.picDest.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.picDest.TabIndex = 1
        Me.picDest.TabStop = False
        "
        "MenuStrip1
        "
        Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuFile})
        Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
        Me.MenuStrip1.Name = "MenuStrip1"
        Me.MenuStrip1.Size = New System.Drawing.Size(522, 24)
        Me.MenuStrip1.TabIndex = 2
        Me.MenuStrip1.Text = "MenuStrip1"
        "
        "mnuFile
        "
        Me.mnuFile.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuFileOpen})
        Me.mnuFile.Name = "mnuFile"
        Me.mnuFile.Text = "&File"
        "
        "mnuFileOpen
        "
        Me.mnuFileOpen.Name = "mnuFileOpen"
        Me.mnuFileOpen.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.O), System.Windows.Forms.Keys)
        Me.mnuFileOpen.Text = "&Open"
        "
        "dlgOpenImage
        "
        Me.dlgOpenImage.Filter = "Bitmap Files (*.bmp)|*.bmp|All Files (*.*)|*.*"
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(522, 273)
        Me.Controls.Add(Me.SplitContainer1)
        Me.Controls.Add(Me.MenuStrip1)
        Me.Name = "Form1"
        Me.Text = "InvertImageUnsafe"
        Me.SplitContainer1.Panel1.ResumeLayout(False)
        Me.SplitContainer1.Panel1.PerformLayout()
        Me.SplitContainer1.Panel2.ResumeLayout(False)
        Me.SplitContainer1.Panel2.PerformLayout()
        Me.SplitContainer1.ResumeLayout(False)
        CType(Me.picSource, System.ruponentModel.ISupportInitialize).EndInit()
        CType(Me.picDest, System.ruponentModel.ISupportInitialize).EndInit()
        Me.MenuStrip1.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()
    End Sub
    Friend WithEvents SplitContainer1 As System.Windows.Forms.SplitContainer
    Friend WithEvents picSource As System.Windows.Forms.PictureBox
    Friend WithEvents picDest As System.Windows.Forms.PictureBox
    Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
    Friend WithEvents mnuFile As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuFileOpen As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents dlgOpenImage As System.Windows.Forms.OpenFileDialog
End Class

Make an image transparent

Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Windows.Forms
public class BitmapTransparent
   public Shared Sub Main
        Application.Run(New TransparencyForm)
   End Sub
End class
Public Class TransparencyForm
    Inherits System.Windows.Forms.Form
#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
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.SetStyle(ControlStyles.DoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    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 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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 splitter2 As System.Windows.Forms.Splitter
    Friend WithEvents splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents panel1 As System.Windows.Forms.Panel
    Friend WithEvents groupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents panel3 As System.Windows.Forms.Panel
    Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents panel2 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.splitter2 = New System.Windows.Forms.Splitter()
        Me.splitter1 = New System.Windows.Forms.Splitter()
        Me.groupBox1 = New System.Windows.Forms.GroupBox()
        Me.panel1 = New System.Windows.Forms.Panel()
        Me.groupBox3 = New System.Windows.Forms.GroupBox()
        Me.panel3 = New System.Windows.Forms.Panel()
        Me.groupBox2 = New System.Windows.Forms.GroupBox()
        Me.panel2 = New System.Windows.Forms.Panel()
        Me.groupBox1.SuspendLayout()
        Me.groupBox3.SuspendLayout()
        Me.groupBox2.SuspendLayout()
        Me.SuspendLayout()
        "
        "splitter2
        "
        Me.splitter2.Location = New System.Drawing.Point(232, 0)
        Me.splitter2.Name = "splitter2"
        Me.splitter2.Size = New System.Drawing.Size(3, 102)
        Me.splitter2.TabIndex = 9
        Me.splitter2.TabStop = False
        "
        "splitter1
        "
        Me.splitter1.Location = New System.Drawing.Point(229, 0)
        Me.splitter1.Name = "splitter1"
        Me.splitter1.Size = New System.Drawing.Size(3, 102)
        Me.splitter1.TabIndex = 6
        Me.splitter1.TabStop = False
        "
        "groupBox1
        "
        Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel1})
        Me.groupBox1.Dock = System.Windows.Forms.DockStyle.Left
        Me.groupBox1.Location = New System.Drawing.Point(117, 0)
        Me.groupBox1.Name = "groupBox1"
        Me.groupBox1.Size = New System.Drawing.Size(300, 102)
        Me.groupBox1.TabIndex = 5
        Me.groupBox1.TabStop = False
        Me.groupBox1.Text = "Original Colors"
        "
        "panel1
        "
        Me.panel1.BackColor = System.Drawing.Color.White
        Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panel1.Location = New System.Drawing.Point(3, 16)
        Me.panel1.Name = "panel1"
        Me.panel1.Size = New System.Drawing.Size(106, 83)
        Me.panel1.TabIndex = 0
        "
        "groupBox3
        "
        Me.groupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel3})
        Me.groupBox3.Dock = System.Windows.Forms.DockStyle.Fill
        Me.groupBox3.Location = New System.Drawing.Point(117, 0)
        Me.groupBox3.Name = "groupBox3"
        Me.groupBox3.Size = New System.Drawing.Size(235, 102)
        Me.groupBox3.TabIndex = 8
        Me.groupBox3.TabStop = False
        Me.groupBox3.Text = "Made Transparent"
        "
        "panel3
        "
        Me.panel3.BackColor = System.Drawing.Color.White
        Me.panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.panel3.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panel3.Location = New System.Drawing.Point(3, 16)
        Me.panel3.Name = "panel3"
        Me.panel3.Size = New System.Drawing.Size(229, 83)
        Me.panel3.TabIndex = 0
        "
        "groupBox2
        "
        Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel2})
        Me.groupBox2.Dock = System.Windows.Forms.DockStyle.Left
        Me.groupBox2.Name = "groupBox2"
        Me.groupBox2.Size = New System.Drawing.Size(117, 102)
        Me.groupBox2.TabIndex = 7
        Me.groupBox2.TabStop = False
        Me.groupBox2.Text = "White Background"
        "
        "panel2
        "
        Me.panel2.BackColor = System.Drawing.Color.White
        Me.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.panel2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panel2.Location = New System.Drawing.Point(3, 16)
        Me.panel2.Name = "panel2"
        Me.panel2.Size = New System.Drawing.Size(111, 83)
        Me.panel2.TabIndex = 0
        "
        "TransparencyForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(352, 102)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.groupBox1})
        Me.Name = "TransparencyForm"
        Me.Text = "TransparencyForm"
        Me.groupBox1.ResumeLayout(False)
        Me.groupBox3.ResumeLayout(False)
        Me.groupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
#End Region

    Dim backgroundString As String = "the quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\nthe quick brown fox jumps over the lazy dog\n"

    Private Sub panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel1.Paint
        Dim g As Graphics = e.Graphics
        Dim bmp As Bitmap = New Bitmap("yourfile.jpg")
        g.DrawString(backgroundString, Me.Font, Brushes.Black, Me.ClientRectangle.Left, Me.ClientRectangle.Top)
        bmp.MakeTransparent(bmp.GetPixel(10, 10))
        Dim rect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
        rect.Offset((Me.panel1.ClientRectangle.Width - rect.Width) / 2, (Me.panel1.ClientRectangle.Height - rect.Height) / 2)
        g.DrawImage(bmp, rect)
    End Sub
    Private Sub TransparencyForm_Layout(ByVal sender As Object, ByVal e As LayoutEventArgs) Handles MyBase.Layout
        panel1.Refresh()
    End Sub
End Class

Mirror an Image

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class RotateImage
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ruponentModel.IContainer
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Panel2 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.SuspendLayout()
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(88, 232)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(64, 24)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "Mirror"
        "
        "Button4
        "
        Me.Button4.Location = New System.Drawing.Point(328, 232)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(56, 24)
        Me.Button4.TabIndex = 5
        Me.Button4.Text = "Exit"
        "
        "Panel1
        "
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel1.Location = New System.Drawing.Point(24, 16)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(200, 184)
        Me.Panel1.TabIndex = 10
        "
        "Panel2
        "
        Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel2.Location = New System.Drawing.Point(248, 16)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(208, 184)
        Me.Panel2.TabIndex = 11
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 286)
        Me.Controls.Add(Me.Panel2)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.ResumeLayout(False)
    End Sub
    Dim pic1, pic2 As Bitmap

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Panel2.Invalidate()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        End
    End Sub
    Private Sub Panel1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim g As Graphics = e.Graphics
        g.DrawImage(pic1, 0, 0)
    End Sub
    Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
        Dim g As Graphics = e.Graphics
        Dim x As Integer = Panel2.Width
        Dim col As Color = New Color
        
        Dim pic4 As Bitmap
        pic4 = New Bitmap(x, x)
        Dim i, j As Integer
        For i = 0 To x - 1
            For j = 0 To x - 1
                col = pic2.GetPixel(i, j)
                pic4.SetPixel(x - i - 1, j, col)
            Next
        Next
        g.DrawImage(pic4, 0, 0)
        pic2 = New Bitmap(pic4)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.Height = Panel1.Width
        Panel2.Width = Panel1.Width
        Panel2.Height = Panel2.Width
        Dim pic As Image = Image.FromFile("YourFile.bmp")
        pic1 = New Bitmap(pic, Panel1.Width, Panel1.Height)
        pic2 = New Bitmap(pic1)
    End Sub
End Class

Move an image and paint

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Drawing.Imaging
public class PanningFormDemo
   public Shared Sub Main
        Application.Run(New PanningForm)
   End Sub
End class
Public Class PanningForm
    Inherits System.Windows.Forms.Form
#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 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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 upButton As System.Windows.Forms.Button
    Friend WithEvents panel1 As System.Windows.Forms.Panel
    Friend WithEvents downButton As System.Windows.Forms.Button
    Friend WithEvents leftButton As System.Windows.Forms.Button
    Friend WithEvents rightButton As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.upButton = New System.Windows.Forms.Button()
        Me.panel1 = New System.Windows.Forms.Panel()
        Me.downButton = New System.Windows.Forms.Button()
        Me.leftButton = New System.Windows.Forms.Button()
        Me.rightButton = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        "upButton
        "
        Me.upButton.Anchor = System.Windows.Forms.AnchorStyles.Top
        Me.upButton.Location = New System.Drawing.Point(132, 10)
        Me.upButton.Name = "upButton"
        Me.upButton.Size = New System.Drawing.Size(24, 23)
        Me.upButton.TabIndex = 5
        Me.upButton.Text = "^"
        "
        "panel1
        "
        Me.panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.panel1.Location = New System.Drawing.Point(36, 43)
        Me.panel1.Name = "panel1"
        Me.panel1.Size = New System.Drawing.Size(216, 184)
        Me.panel1.TabIndex = 2
        "
        "downButton
        "
        Me.downButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom
        Me.downButton.Location = New System.Drawing.Point(132, 234)
        Me.downButton.Name = "downButton"
        Me.downButton.Size = New System.Drawing.Size(24, 23)
        Me.downButton.TabIndex = 6
        Me.downButton.Text = "v"
        "
        "leftButton
        "
        Me.leftButton.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.leftButton.Location = New System.Drawing.Point(6, 124)
        Me.leftButton.Name = "leftButton"
        Me.leftButton.Size = New System.Drawing.Size(24, 23)
        Me.leftButton.TabIndex = 3
        Me.leftButton.Text = "<"
        "
        "rightButton
        "
        Me.rightButton.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.rightButton.Location = New System.Drawing.Point(262, 124)
        Me.rightButton.Name = "rightButton"
        Me.rightButton.Size = New System.Drawing.Size(24, 23)
        Me.rightButton.TabIndex = 4
        Me.rightButton.Text = ">"
        "
        "PanningForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.upButton, Me.panel1, Me.downButton, Me.leftButton, Me.rightButton})
        Me.Name = "PanningForm"
        Me.Text = "PanningForm"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Dim bmp As Bitmap = New Bitmap("yourfile.jpg")
    Dim offset As Size = New Size(0, 0)
    Private Sub panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel1.Paint
        Dim g As Graphics = e.Graphics
        Dim destRect As Rectangle = Me.panel1.ClientRectangle
        Dim srcRect As Rectangle = New Rectangle(offset.Width, offset.Height, destRect.Width, destRect.Height)
        g.DrawImage(bmp, destRect, srcRect, g.PageUnit)
    End Sub
    Private Sub upButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles upButton.Click
        offset.Height = offset.Height + 10
        panel1.Refresh()
    End Sub
    Private Sub downButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downButton.Click
        offset.Height = offset.Height - 10
        panel1.Refresh()
    End Sub
    Private Sub rightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rightButton.Click
        offset.Width = offset.Width + 10
        panel1.Refresh()
    End Sub
    Private Sub leftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles leftButton.Click
        offset.Width = offset.Width - 10
        panel1.Refresh()
    End Sub
End Class

Rotate an Image

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class RotateImage
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ruponentModel.IContainer
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Panel2 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.SuspendLayout()
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(88, 232)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(64, 24)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "Rotate"
        "
        "Button4
        "
        Me.Button4.Location = New System.Drawing.Point(328, 232)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(56, 24)
        Me.Button4.TabIndex = 5
        Me.Button4.Text = "Exit"
        "
        "Panel1
        "
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel1.Location = New System.Drawing.Point(24, 16)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(200, 184)
        Me.Panel1.TabIndex = 10
        "
        "Panel2
        "
        Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel2.Location = New System.Drawing.Point(248, 16)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(208, 184)
        Me.Panel2.TabIndex = 11
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 286)
        Me.Controls.Add(Me.Panel2)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.ResumeLayout(False)
    End Sub
    Dim pic1, pic2 As Bitmap

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Panel2.Invalidate()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        End
    End Sub
    Private Sub Panel1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim g As Graphics = e.Graphics
        g.DrawImage(pic1, 0, 0)
    End Sub
    Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
        Dim g As Graphics = e.Graphics
        Dim x As Integer = Panel2.Width
        Dim col As Color = New Color
        
        Dim pic3 As Bitmap
        pic3 = New Bitmap(x, x)
        Dim i, j As Integer
        For i = 0 To x - 1
            For j = 0 To x - 1
                col = pic2.GetPixel(i, j)
                pic3.SetPixel(i, x - 1 - j, col)
            Next
        Next
        g.DrawImage(pic3, 0, 0)
        pic2 = New Bitmap(pic3)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.Height = Panel1.Width
        Panel2.Width = Panel1.Width
        Panel2.Height = Panel2.Width
        Dim pic As Image = Image.FromFile("YourFile.bmp")
        pic1 = New Bitmap(pic, Panel1.Width, Panel1.Height)
        pic2 = New Bitmap(pic1)
    End Sub
End Class

Scale an image

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Drawing.Imaging
public class ScalingClippingFormDemo
   public Shared Sub Main
        Application.Run(New ScalingClippingForm)
   End Sub
End class

Public Class ScalingClippingForm
    Inherits System.Windows.Forms.Form
#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
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.SetStyle(ControlStyles.DoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    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 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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 splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents panel1 As System.Windows.Forms.Panel
    Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents panel2 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.splitter1 = New System.Windows.Forms.Splitter()
        Me.groupBox1 = New System.Windows.Forms.GroupBox()
        Me.panel1 = New System.Windows.Forms.Panel()
        Me.groupBox2 = New System.Windows.Forms.GroupBox()
        Me.panel2 = New System.Windows.Forms.Panel()
        Me.groupBox1.SuspendLayout()
        Me.groupBox2.SuspendLayout()
        Me.SuspendLayout()
        "
        "splitter1
        "
        Me.splitter1.Location = New System.Drawing.Point(184, 0)
        Me.splitter1.Name = "splitter1"
        Me.splitter1.Size = New System.Drawing.Size(3, 182)
        Me.splitter1.TabIndex = 4
        Me.splitter1.TabStop = False
        "
        "groupBox1
        "
        Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel1})
        Me.groupBox1.Dock = System.Windows.Forms.DockStyle.Left
        Me.groupBox1.Name = "groupBox1"
        Me.groupBox1.Size = New System.Drawing.Size(184, 182)
        Me.groupBox1.TabIndex = 3
        Me.groupBox1.TabStop = False
        Me.groupBox1.Text = "Scaling"
        "
        "panel1
        "
        Me.panel1.BackColor = System.Drawing.Color.White
        Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panel1.Location = New System.Drawing.Point(3, 16)
        Me.panel1.Name = "panel1"
        Me.panel1.Size = New System.Drawing.Size(178, 163)
        Me.panel1.TabIndex = 0
        "
        "groupBox2
        "
        Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel2})
        Me.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.groupBox2.Name = "groupBox2"
        Me.groupBox2.Size = New System.Drawing.Size(392, 182)
        Me.groupBox2.TabIndex = 5
        Me.groupBox2.TabStop = False
        Me.groupBox2.Text = "Clipping"
        "
        "panel2
        "
        Me.panel2.BackColor = System.Drawing.Color.White
        Me.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.panel2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panel2.Location = New System.Drawing.Point(3, 16)
        Me.panel2.Name = "panel2"
        Me.panel2.Size = New System.Drawing.Size(386, 163)
        Me.panel2.TabIndex = 0
        "
        "ScalingClippingForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(392, 182)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.splitter1, Me.groupBox1, Me.groupBox2})
        Me.Name = "ScalingClippingForm"
        Me.Text = "ScalingClippingFor"
        Me.groupBox1.ResumeLayout(False)
        Me.groupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
#End Region

    Private Sub panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel1.Paint
        Dim g As Graphics = e.Graphics
        Dim bmp As Bitmap = New Bitmap("yourfile.jpg")
        Dim rect As Rectangle = New Rectangle(10, 10, Me.panel1.ClientRectangle.Width - 20, Me.panel1.ClientRectangle.Height - 20)
        g.DrawImage(bmp, rect)
        g.DrawRectangle(Pens.Black, rect)
    End Sub
End Class

Scale image with different Graphics Units

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Drawing.Imaging
public class ScalingClippingUnit
   public Shared Sub Main
        Application.Run(New ScalingClippingForm)
   End Sub
End class

Public Class ScalingClippingForm
    Inherits System.Windows.Forms.Form
#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
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.SetStyle(ControlStyles.DoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    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 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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 splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents panel1 As System.Windows.Forms.Panel
    Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents panel2 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.splitter1 = New System.Windows.Forms.Splitter()
        Me.groupBox1 = New System.Windows.Forms.GroupBox()
        Me.panel1 = New System.Windows.Forms.Panel()
        Me.groupBox2 = New System.Windows.Forms.GroupBox()
        Me.panel2 = New System.Windows.Forms.Panel()
        Me.groupBox1.SuspendLayout()
        Me.groupBox2.SuspendLayout()
        Me.SuspendLayout()
        "
        "splitter1
        "
        Me.splitter1.Location = New System.Drawing.Point(184, 0)
        Me.splitter1.Name = "splitter1"
        Me.splitter1.Size = New System.Drawing.Size(3, 182)
        Me.splitter1.TabIndex = 4
        Me.splitter1.TabStop = False
        "
        "groupBox1
        "
        Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel1})
        Me.groupBox1.Dock = System.Windows.Forms.DockStyle.Left
        Me.groupBox1.Name = "groupBox1"
        Me.groupBox1.Size = New System.Drawing.Size(184, 182)
        Me.groupBox1.TabIndex = 3
        Me.groupBox1.TabStop = False
        Me.groupBox1.Text = "Scaling"
        "
        "panel1
        "
        Me.panel1.BackColor = System.Drawing.Color.White
        Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panel1.Location = New System.Drawing.Point(3, 16)
        Me.panel1.Name = "panel1"
        Me.panel1.Size = New System.Drawing.Size(178, 163)
        Me.panel1.TabIndex = 0
        "
        "groupBox2
        "
        Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel2})
        Me.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.groupBox2.Name = "groupBox2"
        Me.groupBox2.Size = New System.Drawing.Size(392, 182)
        Me.groupBox2.TabIndex = 5
        Me.groupBox2.TabStop = False
        Me.groupBox2.Text = "Clipping"
        "
        "panel2
        "
        Me.panel2.BackColor = System.Drawing.Color.White
        Me.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.panel2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panel2.Location = New System.Drawing.Point(3, 16)
        Me.panel2.Name = "panel2"
        Me.panel2.Size = New System.Drawing.Size(386, 163)
        Me.panel2.TabIndex = 0
        "
        "ScalingClippingForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(392, 182)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.splitter1, Me.groupBox1, Me.groupBox2})
        Me.Name = "ScalingClippingForm"
        Me.Text = "ScalingClippingFor"
        Me.groupBox1.ResumeLayout(False)
        Me.groupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
#End Region

    Private Sub panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel1.Paint
        Dim g As Graphics = e.Graphics
        Dim bmp As Bitmap = New Bitmap("yourfile.jpg")
        Dim destRect As Rectangle = New Rectangle(10, 10, Me.panel2.ClientRectangle.Width - 20, Me.panel2.ClientRectangle.Height - 20)
        Dim srcRect As Rectangle = New Rectangle(0, 0, destRect.Width, destRect.Height)
        g.DrawImage(bmp, destRect, srcRect, g.PageUnit)
        g.DrawRectangle(Pens.Black, destRect)
    End Sub
End Class

Skew an Image

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class SkewImage
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim curImage As Image = Image.FromFile("yourfile.jpg")
        e.Graphics.Clear(Me.BackColor)
        Dim pts As Point() = {New Point(150, 20), New Point(20, 50), New Point(150, 300)}
        e.Graphics.DrawImage(curImage, pts)
        
  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class

Skew image

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class SkewingDemo
   public Shared Sub Main
        Application.Run(New SkewingForm)
   End Sub
End class

Public Class SkewingForm
    Inherits System.Windows.Forms.Form
#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 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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 upButton As System.Windows.Forms.Button
    Friend WithEvents panel1 As System.Windows.Forms.Panel
    Friend WithEvents downButton As System.Windows.Forms.Button
    Friend WithEvents leftButton As System.Windows.Forms.Button
    Friend WithEvents rightButton As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.upButton = New System.Windows.Forms.Button()
        Me.panel1 = New System.Windows.Forms.Panel()
        Me.downButton = New System.Windows.Forms.Button()
        Me.leftButton = New System.Windows.Forms.Button()
        Me.rightButton = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        "upButton
        "
        Me.upButton.Anchor = System.Windows.Forms.AnchorStyles.Top
        Me.upButton.Location = New System.Drawing.Point(132, 10)
        Me.upButton.Name = "upButton"
        Me.upButton.Size = New System.Drawing.Size(24, 23)
        Me.upButton.TabIndex = 5
        Me.upButton.Text = "^"
        "
        "panel1
        "
        Me.panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.panel1.Location = New System.Drawing.Point(36, 43)
        Me.panel1.Name = "panel1"
        Me.panel1.Size = New System.Drawing.Size(216, 184)
        Me.panel1.TabIndex = 2
        "
        "downButton
        "
        Me.downButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom
        Me.downButton.Location = New System.Drawing.Point(132, 234)
        Me.downButton.Name = "downButton"
        Me.downButton.Size = New System.Drawing.Size(24, 23)
        Me.downButton.TabIndex = 6
        Me.downButton.Text = "v"
        "
        "leftButton
        "
        Me.leftButton.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.leftButton.Location = New System.Drawing.Point(6, 124)
        Me.leftButton.Name = "leftButton"
        Me.leftButton.Size = New System.Drawing.Size(24, 23)
        Me.leftButton.TabIndex = 3
        Me.leftButton.Text = "<"
        "
        "rightButton
        "
        Me.rightButton.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.rightButton.Location = New System.Drawing.Point(262, 124)
        Me.rightButton.Name = "rightButton"
        Me.rightButton.Size = New System.Drawing.Size(24, 23)
        Me.rightButton.TabIndex = 4
        Me.rightButton.Text = ">"
        "
        "SkewingForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.upButton, Me.panel1, Me.downButton, Me.leftButton, Me.rightButton})
        Me.Name = "SkewingForm"
        Me.Text = "SkewingForm"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Dim bmp As Bitmap = New Bitmap("yourfile.jpg")
    Dim offset As Size = New Size(0, 0)
    Private Sub panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel1.Paint
        Dim g As Graphics = e.Graphics
        Dim rect As Rectangle = Me.panel1.ClientRectangle
        Dim points As Point() = New Point() { _
            New Point(rect.Left + offset.Width, rect.Top + offset.Height), _
            New Point(rect.Right, rect.Top + offset.Height), _
            New Point(rect.Left, rect.Bottom - offset.Height)}
        g.DrawImage(bmp, points)
    End Sub
    Private Sub upButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upButton.Click
        offset.Height = offset.Height + 10
        panel1.Refresh()
    End Sub

    Private Sub leftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles leftButton.Click
        offset.Width = offset.Width - 10
        panel1.Refresh()
    End Sub
    Private Sub downButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downButton.Click
        offset.Height = offset.Height - 10
        panel1.Refresh()
    End Sub
    Private Sub rightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rightButton.Click
        offset.Width = offset.Width + 10
        panel1.Refresh()
    End Sub
End Class

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 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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(5, 13)
        Me.ClientSize = New System.Drawing.Size(496, 378)
        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.EventArgs) Handles 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.EventArgs) Handles 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.EventArgs) Handles 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.EventArgs) Handles Zoom100Menu.Click
        imgHeight = imgHeight
        imgWidth = imgWidth
        Invalidate()
    End Sub
    Private Sub Zoom200Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 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.EventArgs) Handles 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 Nothing) Then
            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.EventArgs) Handles Skewing25Menu.Click
        Dim g As Graphics = Me.CreateGraphics()
        g.Clear(Me.BackColor)
        Dim pts As Point() = {New Point(150, 20), New Point(20, 50), New Point(150, 300)}
        g.DrawImage(curImage, pts)
        g.Dispose()
    End Sub
End Class

Zoom Image

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class ZoomImage
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim newImage As Image = Image.FromFile("yourfile.jpg")
        
        e.Graphics.DrawImage(newImage, New Rectangle(0, 0, 100, 100))
  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class