Image Filter Effect 1 : Image Filter « 2D Graphics « VB.Net Tutorial

Home
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.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » 2D Graphics » Image Filter 
17.48.1.Image Filter Effect 1
'Visual Basic.Net JingCai Programming 100 Examples
'Author: Yong Zhang
'Publisher: Water Publisher China
'ISBN: 750841156

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

public class ImageFilter1
   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 NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Top
        Me.PictureBox1.Image = Image.FromFile("YourFile.bmp")
        Me.PictureBox1.Location = New System.Drawing.Point(00)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(368248)
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(72280)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(6432)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Effect 1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(368326)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.PictureBox1)
        Me.ResumeLayout(False)

    End Sub

    Dim i, j, rr, gg, bb, r, g, b, a As Integer
    Dim c, cc, cd As System.Drawing.Color
    Dim pic1 As System.Drawing.Bitmap

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
        pic1 = PictureBox1.Image
        Dim rr1, gg1, bb1, rr2, gg2, bb2, r1, r2, r3, b1, b2, b3, g1, g2, g3 As Integer
        For j = To PictureBox1.Size.Width - 1
            For i = To PictureBox1.Size.Height - 1
                c = pic1.GetPixel(j, i)
                r1 = c.R
                g1 = c.G
                b1 = c.B
                a = c.A
                cc = pic1.GetPixel(j + 1, i)
                r2 = cc.R
                g2 = cc.G
                b2 = cc.B
                cd = pic1.GetPixel(j, i + 1)
                r3 = cd.R
                g3 = cd.G
                b3 = cd.B
                rr1 = (r1 - r22
                rr2 = (r1 - r32
                rr = (rr1 + rr20.5
                gg1 = (g1 - g22
                gg2 = (g1 - g32
                gg = (gg1 + gg20.5
                bb1 = (b1 - b22
                bb2 = (b1 - b32
                bb = (bb1 + bb20.5
                If rr < Then rr = 0
                If rr > 255 Then rr = 255
                If gg < Then gg = 0
                If gg > 255 Then gg = 255
                If bb < Then bb = 0
                If bb > 255 Then bb = 255
                c = Color.FromArgb(a, rr, gg, bb)
                pic1.SetPixel(j, i, c)
            Next
            PictureBox1.Refresh()
        Next
    End Sub

End Class
17.48.Image Filter
17.48.1.Image Filter Effect 1
17.48.2.Image filter effect 2
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.