static public Map2d LoadImage(string filename) // give the JSON file name { JObject pfile = null; string json = BaseUtils.FileHelpers.TryReadAllTextFromFile(filename); if (json != null) { try { pfile = (JObject)JObject.Parse(json); Map2d map; if (File.Exists(filename.Replace(".json", ".png"))) { map = new Map2d(filename.Replace(".json", ".png")); } else { map = new Map2d(filename.Replace(".json", ".jpg")); } map.TopLeft = new Point(pfile["x1"].Int(), pfile["y1"].Int()); map.pxTopLeft = new Point(pfile["px1"].Int(), pfile["py1"].Int()); map.TopRight = new Point(pfile["x2"].Int(), pfile["y1"].Int()); map.pxTopRight = new Point(pfile["px2"].Int(), pfile["py1"].Int()); map.BottomLeft = new Point(pfile["x1"].Int(), pfile["y2"].Int()); map.pxBottomLeft = new Point(pfile["px1"].Int(), pfile["py2"].Int()); map.BottomRight = new Point(pfile["x2"].Int(), pfile["y2"].Int()); map.pxBottomRight = new Point(pfile["px2"].Int(), pfile["py2"].Int()); map.Area = (double)(map.TopRight.X - map.TopLeft.X) * (double)(map.TopLeft.Y - map.BottomRight.Y); return(map); } catch { } } return(null); }
public static List <Map2d> LoadFromFolder(string datapath) { List <Map2d> maps = new List <Map2d>(); try { DirectoryInfo dirInfo = new DirectoryInfo(datapath); FileInfo[] allFiles = dirInfo.GetFiles("*.json"); if (allFiles != null) { foreach (FileInfo fi in allFiles) { Map2d map = new Map2d(); if (map.LoadImage(fi.FullName)) { maps.Add(map); } } maps.Sort(delegate(Map2d p1, Map2d p2) // biggest first.. name if same.. { if (p1.Area == p2.Area) { return(p1.FileName.CompareTo(p2.FileName)); } else if (p1.Area < p2.Area) { return(1); } else { return(-1); } } ); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Map exception on load " + ex); } return(maps); }
public static List <Map2d> LoadImages(string datapath) { List <Map2d> maps = new List <Map2d>(); try { DirectoryInfo dirInfo = new DirectoryInfo(datapath); FileInfo[] allFiles = dirInfo.GetFiles("*.json"); if (allFiles != null) { foreach (FileInfo fi in allFiles) { Map2d map = LoadImage(fi.FullName); if (map != null) { maps.Add(map); } } maps.Sort(delegate(Map2d p1, Map2d p2) // biggest first.. name if same.. { if (p1.Area == p2.Area) { return(p1.FileName.CompareTo(p2.FileName)); } else if (p1.Area < p2.Area) { return(1); } else { return(-1); } } ); } } catch { } return(maps); }