using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Diagnostics;
using System.Globalization;
// The 'windowHandle' parameter will contain the window handle for the:
// - Active window when run by hotkey
// - Trigger target when run by a Trigger rule
// - TitleBar Button owner when run by a TitleBar Button
// - Jump List owner when run from a Taskbar Jump List
// - Currently focused window if none of these match
public static class DisplayFusionFunction
{
public static void Run(IntPtr windowHandle)
{
BFS.Clipboard.Copy();
NumberFormatInfo doubleSeparator = new NumberFormatInfo();
doubleSeparator.NumberDecimalSeparator = ".";
foreach (string pictureFiles in Clipboard.GetFileDropList())
{
Bitmap bitmap = new Bitmap(pictureFiles);
var longitude = GetCoordinateDouble(bitmap.GetPropertyItem(4));
var latitude = GetCoordinateDouble(bitmap.GetPropertyItem(2));
Process.Start($"https://www.google.com/maps/preview?q={latitude.ToString(doubleSeparator)},{longitude.ToString(doubleSeparator)}");
}
}
private static double GetCoordinateDouble(PropertyItem propItem)
{
uint degreesNumerator = BitConverter.ToUInt32(propItem.Value, 0);
uint degreesDenominator = BitConverter.ToUInt32(propItem.Value, 4);
double degrees = degreesNumerator / (double)degreesDenominator;
uint minutesNumerator = BitConverter.ToUInt32(propItem.Value, 8);
uint minutesDenominator = BitConverter.ToUInt32(propItem.Value, 12);
double minutes = minutesNumerator / (double)minutesDenominator;
uint secondsNumerator = BitConverter.ToUInt32(propItem.Value, 16);
uint secondsDenominator = BitConverter.ToUInt32(propItem.Value, 20);
double seconds = secondsNumerator / (double)secondsDenominator;
double coorditate = degrees + (minutes / 60d) + (seconds / 3600d);
return coorditate;
}
}