how to define regions on an image
I would like to define regions on an image. Let's assume that I have the map of USA as image 开发者_JAVA技巧and when the mouse hovers one of the states, the message box will prompt the name of the state. In flash, each states are sliced and defined as a region. How an image can be sliced in WPF?
Thanks.
Assuming your map is drawn onto a WPF Canvas at the origin (0,0), that exists on the MainWindow of a new WPF project, what you could do is this:
- In the codebehind file MainWindow.cs, create a Dictionary of "hitboxes" that define square regions on the map, and the relevant US state name.
- Create an event handler for when the mouse moves over your Canvas. This event handler will give you the coordinates of the mouse.
- Search the Dictionary to see which entry contains your current mouse coordinate, and retrieve the state name from the entry (if their is one).
This is pretty broad but without code examples of what you're trying to do it's at least a start.
精彩评论