public static List <FGEImage> LoadImages(string datapath) { List <FGEImage> fgeimages = new List <FGEImage>(); DirectoryInfo dirInfo = new DirectoryInfo(datapath); FileInfo[] allFiles = null; try { allFiles = dirInfo.GetFiles("*.json"); } catch { } if (allFiles != null) { foreach (FileInfo fi in allFiles) { JObject pfile = null; string json = Tools.TryReadAllTextFromFile(fi.FullName); if (json != null) { FGEImage fgeimg; try { pfile = (JObject)JObject.Parse(json); } catch { continue; } if (File.Exists(fi.FullName.Replace(".json", ".png"))) { fgeimg = new FGEImage(fi.FullName.Replace(".json", ".png")); } else { fgeimg = new FGEImage(fi.FullName.Replace(".json", ".jpg")); } fgeimg.TopLeft = new Point(JSONHelper.GetInt(pfile["x1"], 0), JSONHelper.GetInt(pfile["y1"], 0)); fgeimg.pxTopLeft = new Point(JSONHelper.GetInt(pfile["px1"], 0), JSONHelper.GetInt(pfile["py1"], 0)); fgeimg.TopRight = new Point(JSONHelper.GetInt(pfile["x2"], 0), JSONHelper.GetInt(pfile["y1"], 0)); fgeimg.pxTopRight = new Point(JSONHelper.GetInt(pfile["px2"], 0), JSONHelper.GetInt(pfile["py1"], 0)); fgeimg.BottomLeft = new Point(JSONHelper.GetInt(pfile["x1"], 0), JSONHelper.GetInt(pfile["y2"], 0)); fgeimg.pxBottomLeft = new Point(JSONHelper.GetInt(pfile["px1"], 0), JSONHelper.GetInt(pfile["py2"], 0)); fgeimg.BottomRight = new Point(JSONHelper.GetInt(pfile["x2"], 0), JSONHelper.GetInt(pfile["y2"], 0)); fgeimg.pxBottomRight = new Point(JSONHelper.GetInt(pfile["px2"], 0), JSONHelper.GetInt(pfile["py2"], 0)); fgeimg.Area = (double)(fgeimg.TopRight.X - fgeimg.TopLeft.X) * (double)(fgeimg.TopLeft.Y - fgeimg.BottomRight.Y); //Console.WriteLine("img {0} {1}", fgeimg.FileName, fgeimg.Area); fgeimages.Add(fgeimg); } } fgeimages.Sort(delegate(FGEImage p1, FGEImage 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); } } ); } return(fgeimages); }