Results 1 to 10 of 10

Thread: Point(X,Y) without mouse

  1. #1

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Point(X,Y) without mouse

    I need to get the colour of a pixel on a picture control at runtime - for the reason that I wish to know the colour of pixels by calculating the position at different X and Y intervals, so I cannot use the mouse to click on that pixel.
    Any ideas will be appreciated.
    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Point(X,Y) without mouse

    The X and Y can be whatever you want. The mouse has nothing to do with this.

  3. #3

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: Point(X,Y) without mouse

    Then please show me how. I have a picture called picColour and I wish to interrogate the bit on X and Y without a mouse. Thats what I asked.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Point(X,Y) without mouse

    You have to pass values for X and Y, but how you arrive at these is up to you. Type them into two TextBox controls, use two sliders, iterate over values using loops, etc.

    What are you really trying to do? I don't understand.

    Are you making a game called "I'm thinking of a pixel?"

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Point(X,Y) without mouse

    Example, getting the "center" color:

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        If Not Picture Is Nothing Then
            'Size the Form to fit its Picture:
            Width = Width - ScaleWidth + ScaleX(Picture.Width, vbHimetric, ScaleMode)
            Height = Height - ScaleHeight + ScaleY(Picture.Height, vbHimetric, ScaleMode)
        End If
    End Sub
    
    Private Sub mnuGetcenter_Click()
        Dim CenterColor As Long
    
        CenterColor = Point(ScaleWidth / 2, ScaleHeight / 2)
        MsgBox "Color is " _
             & Right$(String$(7, "0") & Hex$(CenterColor), 8)
    End Sub
    Name:  sshot.png
Views: 107
Size:  24.7 KB

  6. #6

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: Point(X,Y) without mouse

    dilettante,
    Yes, let us say we play that game - excellent example.

    PowerPoster: Thanks so much. My helpfile says that a point must refer to an object like in PicTest.Point(X,y). Which object's point is your code referring to?

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Point(X,Y) without mouse

    The object in the global namespace of the module, i.e. the instance of the Form Form1 named Form1 in this case. This is also aliased as the Me name.

    These are all the same thing:
    Code:
    Point(a, b)
    Form1.Point(a, b)
    Me.Point(a, b)
    A 4th case:

    Code:
    Forms(0).Point(a, b)
    Last edited by dilettante; Apr 1st, 2017 at 03:59 PM.

  8. #8

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: Point(X,Y) without mouse

    It seems to be so, but what confuses me is that there is a picture on your form which I presume is a picture control on the form or it is a picture which was loaded into the form like in Set pic = LoadPicture(cdlImport.FileName)
    I have my picture in a picture control, and when I run the following code, it gives me a colour of -1

    Colour = picTest.Point(picX, 0)

  9. #9

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: Point(X,Y) without mouse

    I have found my error thanks. I gave it coordinates outside the picture. Sorry

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Point(X,Y) without mouse

    I had assigned the Picture at design-time.

    Your picX value must be outside the limits of the image.


    Oops - I was too slow!
    Last edited by dilettante; Apr 1st, 2017 at 04:04 PM. Reason: too slow

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width