Erase function in need of tune-up

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C. Alexander

    Erase function in need of tune-up

    Hey all.

    I have a whiteboard type program.

    I have 2 picturebox's (needed for their mousemove/mousedown events)

    Picture1.Pictur e = MyPicture

    ' Here is my hidden picture used to replace (on erase) Picture1
    Picture2.Pictur e = MyPicture
    Picture2.Enable = False

    Both load the same picture, but one is hidden.

    When one draws on Picture1, all is well.
    When they erase when they draw, basically it copies the X/Y from
    Picture2, and puts it back on Picture1.

    I have some code to do this. works well, however it seems to carry alot of
    overhead.
    Sometimes the program blows out completly when erasing with a large 'brush
    size'

    Is there a more effecient way of doing this other than the way I am?

    The code I have for this is the following:

    ' ----------------------------------------------------------------
    ' Start Code
    '
    ' General Declarations
    Private Declare Function GetPixel Lib "gdi32" _
    (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Private MyBrushSize As Long

    Private Sub Picture1_MouseD own _
    (Button As Integer, Shift As Integer, X As Single, Y As Single)

    ' Right-Click is Erase
    If Button = 2 Then
    MyBrushSize = 2
    If BrushSize(0).Va lue = True Then MyBrushSize = 3
    If BrushSize(1).Va lue = True Then MyBrushSize = 5
    If BrushSize(2).Va lue = True Then MyBrushSize = 10
    Call PenErase(X, Y, MyBrushSize)
    End If
    End Sub

    Private Sub Picture1_MouseM ove _
    (Button As Integer, Shift As Integer, X As Single, Y As Single)

    ' Right-Click is Erase
    If Button = 2 Then
    MyBrushSize = 3
    If BrushSize(0).Va lue = True Then MyBrushSize = 3
    If BrushSize(1).Va lue = True Then MyBrushSize = 5
    If BrushSize(2).Va lue = True Then MyBrushSize = 10
    Call PenErase(X, Y, MyBrushSize)
    End If
    End Sub


    Private Sub PenErase(X As Single, Y As Single, Optional width As Long)
    Dim MyX As Single, MyY As Single
    Dim maxXy As Integer
    Dim OldWidth As Long

    OldWidth = Picture1.DrawWi dth
    Picture1.DrawWi dth = 1

    If width Then
    maxXy = width
    Else
    ' I have 3 options for brush sizes
    If BrushSize(0).Va lue = True Then maxXy = 3
    If BrushSize(1).Va lue = True Then maxXy = 5
    If BrushSize(2).Va lue = True Then maxXy = 10
    End If

    Picture1.PSet (X, Y), GetPixel(Pictur e2.hdc, X, Y)

    For MyY = 1 To maxXy
    Picture1.PSet (X, Y + MyY), GetPixel(Pictur e2.hdc, X, Y + MyY)
    Picture1.PSet (X, Y - MyY), GetPixel(Pictur e2.hdc, X, Y - MyY)

    For MyX = 1 To maxXy
    Picture1.PSet (X - MyX, Y), GetPixel(Pictur e2.hdc, X - MyX, Y) '
    Picture1.PSet (X - MyX, Y - MyY), GetPixel(Pictur e2.hdc, X -
    MyX, Y - MyY)
    Picture1.PSet (X + MyX, Y - MyY), GetPixel(Pictur e2.hdc, X +
    MyX, Y - MyY)
    Picture1.PSet (X + MyX, Y), GetPixel(Pictur e2.hdc, X + MyX, Y)
    Picture1.PSet (X + MyX, Y + MyY), GetPixel(Pictur e2.hdc, X +
    MyX, Y + MyY)
    Picture1.PSet (X - MyX, Y + MyY), GetPixel(Pictur e2.hdc, X -
    MyX, Y + MyY)
    Next MyX

    Next MyY

    Picture1.DrawWi dth = OldWidth
    End Sub

    ' End Code
    ' ----------------------------------------------------------------

    Any help would be appreciated. Thanks :c)




  • Jeff Bennett

    #2
    Re: Erase function in need of tune-up

    To C. Alexander

    I wanted to write back to you on this an another of your
    postings "Using 2 instances of Line and PSet on same image?"
    about a Whiteboard. I think one of our commercial components
    "MetaDraw" may really be very helpful to you but your return
    address from posting is not valid ( even without NoSpam).
    If you are interested please write to me by e-mail with a copy
    of this note and I'll send you some informaiton. Really not
    Spam but specifically directed to what you are trying to do.

    * * Please include a copy of this note with your reply

    Jeff Bennett
    Jeff@Bennet-Tec.Com

    Bennet-Tec Information Systems, Inc
    50 Jericho Tpk, Jericho, NY 11753
    Phone 516 997 5596, Fax - 5597
    Bennet-Tec Information Systems, Inc - offering the industries most Reliable custom controls (OCX/ VBX/ ACTIVEX/ .NET) and custom software development services.


    RELIABLE Component Software
    and Software Development Services
    * TList/Pro * ALLText HT/Pro * MetaDraw *

    =============== ======= =============== =======

    Comment

    Working...