DrawPicture Question

Hi,

Lets say I have a new picture that is Width 100 and Height 100 and I buffered in a drawline line that is only in the middle of the picture Y wise and say the entire length of the picture X wise. g.penheight/penwidth of 2.

The buffered picture is now drawn to via g.drawpicture.

Is it possible using RGBSurface or something to catch a “hit” not on the whole 100x100 picture but only on the line itself within the picture?

Hopefully this makes sense. :slight_smile: Thanks!

Treat you line as an object… that has two points X1,Y1 and X2,Y2

Given your MOUSE point MX,MY calculate how far it is from the vector of your line

I’d give you the code I use… but Snapdragon subclasses a more complex algorith that treats a line as if it were a Quad Bezier Curve (so I can reuse the code for both Lines and Curves)

But google will find it for you… just make sure you use code for a LINE SEGMENT… not for a “LINE” (infinite length)

Direct answer to your question… Yes… if you line is always a UNIQUE color… and ALIAS might blend/blur that making it more difficult… and no matter what… slower than a pure mathematical solution.

Thanks Dave. My app is much more simple than SnapDragon drawing wise. My app doesn’t have a need for curve lines etc. and where I am trying to only “hit” the line when over the line vs. the picture (already in my one object class).

If the line is always horizontal, as is implied in your first post (unless I’m reading it wrong), the math is very simple.

My example was the horizontal but it can be in any direction Tim. Thank you for asking that question for me to clarify.

Here is example of my code that I would normally “find a hit” on any object on my canvas

  [code]  If X >= pictureobject(i).LeftX And X <= pictureobject(i).RightX And Y >= pictureobject(i).TopY And Y <= pictureobject(i).BottomY Then

// do stuff
end if
[/code]

In my situation of my picture object having 100x100 w/h but the line being a small portion … I always “hit” the picture white space before I get to the line. My question is what code can I use or code style to identify the black pixels in a picture to hit the line?

[code] Dim c As color = pictureObject.graphics.Pixel(X, Y)

if c = &cFFFFFF00 then

MsgBox "Nope"

else

MsgBox "Bingo"

end if [/code]

This will find you any non white clicks in a mousedown.