Search code examples
eventswindows-phone-8distance

Calculate the distance between two fingers in Windows Phone 8


As we know, we can calculate the distance between two fingers in Windows Phone 7 using the toolkit's gesteuresevices. It would be like this:

ManipulationStartedEventArgs.GetPosition(UIElment, fingerIndex);

Is there a similar method in Windows Phone to achieve this without toolkit?


Solution

  • So, you want actual distance between user's fingers in real world, i.e. in centimeters? It should be easy: you need to know distance in pixels, then you need to know physical size of one pixel, and then you multiply.

    Now, to get the physical size of one pixel, you'd need to know the phone's screen size. You'd need to know the phone model for that, which you can get by DeviceStatus class. Then you'd need a database of phone's screen sizes, which you'll need to build yourself. For Nokia phones, you could check official website (here's an example). So, for Lumia 920 size of one pixel is 0,07578125 x 0,075520833 mm.

    Next, you'd need to get the multitouch event. For that, you'd use ManipulatienStarted, ManipulationDelta, and ManiputalionComplete events. See this MSDN article for more info.

    Hope I understood you correct and this will work for you. If you need more info or explanations, just let me know in comments.