⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 图像翻转.vb

📁 这是一本用Visual Studio.NET进行多媒体编程的读物
💻 VB
字号:
Option Strict Off
Option Explicit On
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'对于启动窗体,所创建的第一个实例为默认实例。
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'此调用是 Windows 窗体设计器所必需的。
		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
	'Windows 窗体设计器所必需的
	Private components As System.ComponentModel.IContainer
	Public ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents CommonDialog1 As AxMSComDlg.AxCommonDialog
    Public WithEvents Addpicture As System.Windows.Forms.Button
    Public WithEvents Command1 As Microsoft.VisualBasic.Compatibility.VB6.ButtonArray
    '注意:以下过程是 Windows 窗体设计器所必需的
	'可以使用 Windows 窗体设计器来修改它。
	'不要使用代码编辑器来修改它。
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Picture1 As System.Windows.Forms.PictureBox
    Friend WithEvents Button4 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.CommonDialog1 = New AxMSComDlg.AxCommonDialog()
        Me.Addpicture = New System.Windows.Forms.Button()
        Me.Command1 = New Microsoft.VisualBasic.Compatibility.VB6.ButtonArray(Me.components)
        Me.Button1 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.Picture1 = New System.Windows.Forms.PictureBox()
        Me.Button4 = New System.Windows.Forms.Button()
        CType(Me.CommonDialog1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Command1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'CommonDialog1
        '
        Me.CommonDialog1.Enabled = True
        Me.CommonDialog1.Location = New System.Drawing.Point(376, 0)
        Me.CommonDialog1.Name = "CommonDialog1"
        Me.CommonDialog1.OcxState = CType(resources.GetObject("CommonDialog1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.CommonDialog1.Size = New System.Drawing.Size(32, 32)
        Me.CommonDialog1.TabIndex = 5
        '
        'Addpicture
        '
        Me.Addpicture.BackColor = System.Drawing.SystemColors.Control
        Me.Addpicture.Cursor = System.Windows.Forms.Cursors.Default
        Me.Addpicture.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Addpicture.Location = New System.Drawing.Point(16, 8)
        Me.Addpicture.Name = "Addpicture"
        Me.Addpicture.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Addpicture.Size = New System.Drawing.Size(80, 32)
        Me.Addpicture.TabIndex = 1
        Me.Addpicture.Text = "加载图形"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(104, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 32)
        Me.Button1.TabIndex = 6
        Me.Button1.Text = "水平翻转"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(192, 8)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(80, 32)
        Me.Button2.TabIndex = 7
        Me.Button2.Text = "垂直翻转"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(280, 8)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(72, 32)
        Me.Button3.TabIndex = 8
        Me.Button3.Text = "退出程序"
        '
        'Picture1
        '
        Me.Picture1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Picture1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Picture1.Location = New System.Drawing.Point(16, 56)
        Me.Picture1.Name = "Picture1"
        Me.Picture1.Size = New System.Drawing.Size(336, 272)
        Me.Picture1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.Picture1.TabIndex = 9
        Me.Picture1.TabStop = False
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(368, 96)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(64, 40)
        Me.Button4.TabIndex = 10
        Me.Button4.Text = "保存图象"
        '
        'Form1
        '
        Me.AutoScale = False
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(440, 351)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button4, Me.Picture1, Me.Button3, Me.Button2, Me.Button1, Me.CommonDialog1, Me.Addpicture})
        Me.Location = New System.Drawing.Point(4, 23)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.CommonDialog1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Command1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "升级支持"
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
    Dim g As Graphics
    Dim BmpPath As String
    Dim myImage As Image

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        g = Picture1.CreateGraphics
        Button1.Enabled = False
        Button2.Enabled = False
    End Sub

    Private Sub Addpicture_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Addpicture.Click
        Dim BMP As String
        Dim OpenFile As String
        CommonDialog1.Flags = MSComDlg.FileOpenConstants.cdlOFNFileMustExist '设置标志
        CommonDialog1.DefaultExt = "bmp" '设置缺省的文件扩展名
        CommonDialog1.Filter = "bmp files|*.bmp|GIF Files|*.GIF|JPEG Files|*.JPEG|All files|*.*" '设置过滤器
        CommonDialog1.ShowOpen()
        If CommonDialog1.FileName <> "" Then
            BmpPath = CommonDialog1.FileName
            myImage = Image.FromFile(BmpPath)  '向 PicSource 控件加载一个图象文件
            Picture1.Image = myImage
            'Picture1.Width = myImage.Width
            'Picture1.Height = myImage.Height
            Button1.Enabled = True
            Button2.Enabled = True
        Else
            MsgBox("Not Open any File ")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        g.Clear(Color.White)
        Dim ulCorner As New Point(Picture1.Width - 1, 0)
        Dim urCorner As New Point(0, 0)
        Dim llCorner As New Point(Picture1.Width - 1, Picture1.Height - 1)

        'Dim ulCorner As New Point(Picture1.Width, 1)
        'Dim urCorner As New Point(1, 1)
        'Dim llCorner As New Point(Picture1.Width, Picture1.Height)
        Dim destPara As Point() = {ulCorner, urCorner, llCorner}
        g.DrawImage(myImage, destPara)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        g.Clear(Color.White)
        Dim ulCorner As New Point(0, Picture1.Height - 1)
        Dim urCorner As New Point(Picture1.Width - 1, Picture1.Height - 1)
        Dim llCorner As New Point(0, 0)

        'Dim ulCorner As New Point(1, Picture1.Height)
        'Dim urCorner As New Point(Picture1.Width, Picture1.Height)
        'Dim llCorner As New Point(1, 1)
        Dim destPara As Point() = {ulCorner, urCorner, llCorner}
        g.DrawImage(myImage, destPara)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Picture1.Image.Save("C:\Zhangzhilong.jpeg", System.Drawing.Imaging.ImageFormat..Jpeg)
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -