Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 13:32

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[vb.net] Paint

Discussion on [vb.net] Paint within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Aug 2012
Posts: 36
Received Thanks: 14
[vb.net] Paint

How create a paint in vb.net ?!
Source code here
Code:
Public Class PaintForm
    Dim g As Graphics
    Dim startLocation As Point
    Dim endLocation As Point
    Dim TempLocation As New Point(-1, -1)
    Dim TempLocation2 As New Point(-1, -1)
    Dim NumberOfAngle As Integer = 0
    Dim drawing As Boolean = False
    Dim CurrentColor As Color = Color.Blue
    Dim CurrentColor2 As Color = Color.LightSkyBlue
    Dim LastImage As New Bitmap(875, 461)
    Dim M1 As New Bitmap(875, 461)
    Dim M2 As New Bitmap(875, 461)
    Dim M3 As New Bitmap(875, 461)
    Dim M4 As New Bitmap(875, 461)
    Dim PenWidth As Single = 1.0F
    Dim PenPoint As Pen
    Dim SavedFileAddress As String = ""
    Dim CurrentFont As Font
    '******************************
    ' *                          ' *
    ' *                          ' *       
    ' *     By NoCheatImPGM      ' *
    ' *                          ' *
    ' *                          ' *
    '******************************
    Function FillRegion(ByVal X As Integer, ByVal Y As Integer, ByVal FillCol As Color) As Boolean
        If X < 0 Or X > LastImage.Width Or Y < 0 Or Y > LastImage.Height Then
            Return False

        End If

        Application.DoEvents()

        Dim points As Stack = New Stack
        points.Push(New Point(X, Y))

        Dim Pointcolor As Color = LastImage.GetPixel(X, Y)


        Do
            Dim p As Point = CType(points.Pop(), Point)

            LastImage.SetPixel(p.X, p.Y, FillCol)

            If UpPixelHaseSameColor(p.X, p.Y, Pointcolor) Then
                points.Push(New Point(p.X, p.Y - 1))
            End If

            If DownPixelHaseSameColor(p.X, p.Y, Pointcolor) Then
                points.Push(New Point(p.X, p.Y + 1))
            End If


            If RightPixelHaseSameColor(p.X, p.Y, Pointcolor) Then
                points.Push(New Point(p.X + 1, p.Y))
            End If

            If LeftPixelHaseSameColor(p.X, p.Y, Pointcolor) Then
                points.Push(New Point(p.X - 1, p.Y))
            End If

        Loop While points.Count > 0

        Return True

    End Function
    Function UpPixelHaseSameColor(ByVal X As Integer, ByVal Y As Integer, ByVal Col As Color) As Boolean
        Dim result As Boolean = False
        If (Y > 0) Then
            If (LastImage.GetPixel(X, Y - 1) = Col) Then
                result = True
            End If

        End If
        Return result

    End Function
    Function DownPixelHaseSameColor(ByVal X As Integer, ByVal Y As Integer, ByVal Col As Color) As Boolean
        Dim result As Boolean = False
        If (Y < LastImage.Height - 1) Then
            If (LastImage.GetPixel(X, Y + 1) = Col) Then
                result = True
            End If

        End If
        Return result

    End Function
    Function RightPixelHaseSameColor(ByVal X As Integer, ByVal Y As Integer, ByVal Col As Color) As Boolean
        Dim result As Boolean = False
        If (X < LastImage.Width - 1) Then
            If (LastImage.GetPixel(X + 1, Y) = Col) Then
                result = True
            End If

        End If

        Return result

    End Function
    Function LeftPixelHaseSameColor(ByVal X As Integer, ByVal Y As Integer, ByVal Col As Color) As Boolean

        Dim result As Boolean = False
        If (X > 0) Then
            If (LastImage.GetPixel(X - 1, Y) = Col) Then
                result = True
            End If
        End If


        Return result

    End Function
    Sub UpdateImage()

        g = Graphics.FromImage(LastImage)

        Me.PictureBox1.Image = LastImage

    End Sub
    Sub ReloadPen(ByVal PenWd As Single, ByVal CurColor As Color)
        PenPoint = New Pen(CurColor, PenWd)

    End Sub
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            If drawing = False Then

                startLocation = e.Location

                drawing = True

                If MultiAngleRadioButton.Checked Then

                    If TempLocation.X = -1 Then
                        TempLocation = startLocation
                        TempLocation2 = startLocation
                    End If

                    endLocation = e.Location
                    g.DrawLine(PenPoint, TempLocation, endLocation)
                    TempLocation = endLocation

                ElseIf TriangleRadioButton.Checked Then
                    If TempLocation.X = -1 Then
                        TempLocation = startLocation
                        TempLocation2 = startLocation
                    End If

                    If NumberOfAngle <= 2 Then

                        endLocation = e.Location
                        g.DrawLine(PenPoint, TempLocation, endLocation)
                        TempLocation = endLocation

                        If NumberOfAngle = 2 Then
                            g.DrawLine(PenPoint, TempLocation, TempLocation2)
                            TempLocation = New Point(-1, -1)
                            NumberOfAngle = 0
                        Else
                            NumberOfAngle += 1
                        End If


                    End If


                End If


            End If

        ElseIf e.Button = Windows.Forms.MouseButtons.Right Then

            If MultiAngleRadioButton.Checked Then
                If TempLocation.X <> -1 Then
                    endLocation = e.Location
                    g.DrawLine(PenPoint, TempLocation, TempLocation2)
                    TempLocation = New Point(-1, -1)
                End If

            End If




        End If

    End Sub
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If drawing = True Then
            If LineRadioButton.Checked Then
                g.DrawLine(PenPoint, startLocation.X, startLocation.Y, e.X, e.Y)
                startLocation = e.Location
                UpdateImage()

            ElseIf EraserRadioButton.Checked Then

                Dim p As New Pen(Color.White, PenWidth)

                g.DrawLine(p, startLocation.X, startLocation.Y, e.X, e.Y)
                startLocation = e.Location
                UpdateImage()

            End If

        End If
    End Sub
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp

        If drawing Then

            If RectangleRadioButton.Checked Then

                endLocation = e.Location

                Dim s As Point

                s.X = endLocation.X - startLocation.X
                If s.X < 0 Then
                    startLocation.X = endLocation.X

                End If

                s.Y = endLocation.Y - startLocation.Y
                If s.Y < 0 Then
                    startLocation.Y = endLocation.Y

                End If

                s.X = Math.Abs(s.X)
                s.Y = Math.Abs(s.Y)
                g.DrawRectangle(PenPoint, New Rectangle(startLocation, s))

            ElseIf GradientRectAngleRadioButton.Checked Then

                endLocation = e.Location

                Dim s As Point


                If s.X < 0 Then
                    startLocation.X = endLocation.X
                ElseIf s.X = 0 Then
                    s.X = 1
                End If

                s.Y = endLocation.Y - startLocation.Y

                If s.Y < 0 Then
                    startLocation.Y = endLocation.Y
                ElseIf s.Y = 0 Then
                    s.Y = 1
                End If

                s.X = Math.Abs(s.X)
                s.Y = Math.Abs(s.Y)

                Dim b As Brush
                b = New Drawing2D.LinearGradientBrush(New Rectangle(startLocation, s), CurrentColor, CurrentColor2, Drawing2D.LinearGradientMode.BackwardDiagonal)
                g.FillRectangle(b, New Rectangle(startLocation, s))

            ElseIf CircleRadioButton.Checked Then

                endLocation = e.Location
                Dim s As Point

                s.X = endLocation.X - startLocation.X

                If s.X < 0 Then
                    startLocation.X = endLocation.X

                End If

                s.Y = endLocation.Y - startLocation.Y

                If s.Y < 0 Then
                    startLocation.Y = endLocation.Y

                End If

                s.X = Math.Abs(s.X)
                s.Y = Math.Abs(s.Y)

                If s.X > s.Y Then
                    s.Y = s.X
                Else
                    s.X = s.Y
                End If

                g.DrawEllipse(PenPoint, New Rectangle(startLocation, s))

            ElseIf ArcRadioButton.Checked Then
                endLocation = e.Location

                Dim s As Point

                s.X = endLocation.X - startLocation.X

                If s.X < 0 Then
                    startLocation.X = endLocation.X

                End If

                s.Y = endLocation.Y - startLocation.Y

                If s.Y < 0 Then
                    startLocation.Y = endLocation.Y

                End If

                s.X = Math.Abs(s.X)
                s.Y = Math.Abs(s.Y)

                If s.X > s.Y Then
                    s.Y = s.X
                Else
                    s.X = s.Y
                End If

                g.DrawArc(PenPoint, New Rectangle(startLocation, s), 0, -180)

            ElseIf ParallelepipedRadioButton.Checked Then

                endLocation = e.Location

                Dim s As Point

                s.X = endLocation.X - startLocation.X

                If s.X < 0 Then
                    Dim tmp As Integer = startLocation.X
                    startLocation.X = endLocation.X
                    endLocation.X = tmp
                End If

                s.Y = endLocation.Y - startLocation.Y

                If s.Y < 0 Then
                    Dim tmp As Integer = startLocation.Y
                    startLocation.Y = endLocation.Y
                    endLocation.Y = tmp
                End If

                s.X = Math.Abs(s.X)
                s.Y = Math.Abs(s.Y)



                Dim p(3) As Point

                p(0) = New Point(startLocation.X + s.X / 5, startLocation.Y)
                p(1) = New Point(startLocation.X + s.X, startLocation.Y)

                p(2) = New Point(endLocation.X - s.X / 5, endLocation.Y)
                p(3) = New Point(endLocation.X - s.X, endLocation.Y)

                g.DrawPolygon(PenPoint, p)

            ElseIf FillRadioButton.Checked Then
                FillRegion(e.X, e.Y, CurrentColor)

            ElseIf TextRadioButton.Checked Then
                Dim txt As String = Me.TextDrawTextBox.Text
                g.DrawString(txt, CurrentFont, New Drawing2D.HatchBrush(Drawing2D.HatchStyle.BackwardDiagonal, CurrentColor), e.X, e.Y)

            End If

        End If

        drawing = False

        UpdateImage()

    End Sub
    Private Sub PaintForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        CurrentFont = Me.Font
        FontButton.Text = CurrentFont.ToString

        Me.ColorButton.BackColor = Color.Black
        Me.Color2Button.BackColor = Color.Red
        g = Graphics.FromImage(LastImage)
        g.Clear(Color.White)
        UpdateImage()
        ReloadPen(PenWidth, CurrentColor)


    End Sub
    Private Sub ColorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorButton.Click
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            CurrentColor = ColorDialog1.Color
            Me.ColorButton.BackColor = CurrentColor
            ReloadPen(PenWidth, CurrentColor)
        End If



    End Sub
    Private Sub Color2Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Color2Button.Click
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            CurrentColor2 = ColorDialog1.Color
            Me.Color2Button.BackColor = CurrentColor2
        End If
    End Sub
    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        ClearScreen()
    End Sub
    Sub ClearScreen()
        LastImage = New Bitmap(501, 501)
        g = Graphics.FromImage(LastImage)
        g.Clear(Color.White)
        UpdateImage()
    End Sub
    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        If SavedFileAddress = "" Then
            SaveFileDialog1.Filter = "Bitmap File (*.bmp)|*.bmp"
            If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                SavedFileAddress = SaveFileDialog1.FileName



                LastImage.Save(SavedFileAddress)
                Me.Text = SaveFileDialog1.FileName
            End If

        Else
            LastImage.Save(SavedFileAddress)
            Me.Text = SaveFileDialog1.FileName
        End If
       


    End Sub
    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
        SaveFileDialog1.Filter = "Bitmap File (*.bmp)|*.bmp"
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            SavedFileAddress = SaveFileDialog1.FileName

            LastImage.Save(SavedFileAddress)
            Me.Text = SaveFileDialog1.FileName
        End If
    End Sub
    Private Sub TriangleRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TriangleRadioButton.CheckedChanged
        TempLocation = New Point(-1, -1)
    End Sub
    Private Sub P1RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles P1RadioButton.CheckedChanged
        PenWidth = 1.0F
        ReloadPen(PenWidth, CurrentColor)

    End Sub
    Private Sub P2RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles P2RadioButton.CheckedChanged
        PenWidth = 5.0F
        ReloadPen(PenWidth, CurrentColor)
    End Sub
    Private Sub P3RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles P3RadioButton.CheckedChanged
        PenWidth = 10.0F
        ReloadPen(PenWidth, CurrentColor)
    End Sub
    Private Sub M1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M1ToolStripMenuItem.Click
        M1 = LastImage.Clone()
    End Sub
    Private Sub M2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M2ToolStripMenuItem.Click
        M2 = LastImage.Clone()
    End Sub
    Private Sub M3ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M3ToolStripMenuItem.Click
        M3 = LastImage.Clone()
    End Sub
    Private Sub M4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M4ToolStripMenuItem.Click
        M4 = LastImage.Clone()
    End Sub
    Private Sub S1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S1ToolStripMenuItem.Click
        LastImage = M1.Clone
        UpdateImage()
    End Sub
    Private Sub S2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S2ToolStripMenuItem.Click
        LastImage = M2.Clone
        UpdateImage()
    End Sub
    Private Sub S3ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S3ToolStripMenuItem.Click
        LastImage = M3.Clone
        UpdateImage()
    End Sub
    Private Sub S4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S4ToolStripMenuItem.Click
        LastImage = M4.Clone
        UpdateImage()
    End Sub
    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
        If SavedFileAddress = "" Then
            Dim result As Integer = MsgBox("Would you like to save this picture", MsgBoxStyle.YesNo)
            If result = MsgBoxResult.Yes Then
                SaveFileDialog1.Filter = "Bitmap File (*.bmp)|*.bmp" & "NoCheatImPGM Extansion (*.PGM) | *.PGM"
                If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    SavedFileAddress = SaveFileDialog1.FileName

                    LastImage.Save(SavedFileAddress)
                    Me.Text = SaveFileDialog1.FileName
                End If
            End If
        End If
        g.Clear(Color.White)
        UpdateImage()
        SavedFileAddress = ""
    End Sub
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        If SavedFileAddress = "" Then
            Dim result As Integer = MsgBox("Would you like to save the image before exiting?", MsgBoxStyle.YesNoCancel)
            If result = MsgBoxResult.Yes Then
                SaveFileDialog1.Filter = "Bitmap File (*.bmp)|*.bmp"
                If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    SavedFileAddress = SaveFileDialog1.FileName
                    LastImage.Save(SavedFileAddress)
                    Me.Text = SaveFileDialog1.FileName
                End If

            ElseIf result = MsgBoxResult.No Then
                End
            End If
        End If
    End Sub
    Private Sub TextRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextRadioButton.CheckedChanged
        If Me.TextRadioButton.Checked = True Then
            Me.TextDrawTextBox.Visible = True
            FontButton.Visible = True
        Else
            Me.TextDrawTextBox.Visible = False
            FontButton.Visible = False
        End If
    End Sub
    Private Sub FontButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontButton.Click
        If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            CurrentFont = FontDialog1.Font
            FontButton.Text = CurrentFont.ToString
        End If
    End Sub
    Private Sub MessageLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MsgBox("This is a simple tool created by NoCheatImPGM & Co. Thanks for using.", MsgBoxStyle.Information)
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub

    Private Sub LineRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LineRadioButton.CheckedChanged

    End Sub
End Class
Screen shot :
YbasIc~ is offline  
Thanks
2 Users
Old 10/21/2012, 18:26   #2
 
elite*gold: 83
Join Date: Sep 2012
Posts: 1,508
Received Thanks: 79
with GDI+
Gamekeystore is offline  
Thanks
2 Users
Old 10/21/2012, 21:12   #3
 
elite*gold: 0
Join Date: Oct 2012
Posts: 7
Received Thanks: 5
good idea my friend
NoCheаtImPGM is offline  
Thanks
2 Users
Old 10/22/2012, 00:40   #4
 
elite*gold: 0
Join Date: Aug 2012
Posts: 36
Received Thanks: 14
Yeah I think too ^^
YbasIc~ is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
paint.net
11/01/2011 - General Art - 1 Replies
Hi ich habe ne frage zu paint.net, nähmlich wie setze ich ein bild auf ein anderes drauf? Ich will ein "Atomkraft nein Danke" Symbol auf ein anderes Bild raufgeben, wie geht das?
[Paint.NET] Slicen, mit Paint.NET?
05/04/2010 - General Art - 0 Replies
Schönen, guten Abend! Ich hoffe mal, dass ich hier richtig bin, ansonsten einfach verschieben, bitte. Also, ich wollte mich noch mal mit einer Frage melden: Ich bin gerade am Arbeiten, mit Paint.NET. Nun habe ich ein Bild vor mir (Homepagedesign), dass ich slicen will. Nur leider weiß ich nicht, wie das mit diesem Bilderbearbeitungsprogramm gehen soll.
paint.Net
03/22/2010 - WarRock - 7 Replies
also ich kann immer keine Datein abspeichern also warrock texturen oder so mit paint.net ... da steht denn i wie du kannst nicht speichern ...
Paint.NET
01/19/2010 - Off Topic - 17 Replies
Hi ich suche den download für Paint.NET v3.36 Gebe thx :D
Add-on für Paint.net
01/14/2010 - Main - 3 Replies
http://www.elitepvpers.com/forum/epvp-artists-tutor ials/318958-how-metin2-signatur-mit-paint-net.html In diesem Thread ist ein Video, da benutzt der sowas bei Paint.net damit er in die Signatur so blumen musster unso was rein machen kann. Wo gibts das? wie heißt das?



All times are GMT +2. The time now is 13:32.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.