private void PrepareData() { originalForm = BitmapUtils.LoadBitmap(path); Bitmap smallForm = BitmapUtils.Resize(originalForm, smallImageWidth, originalForm.Height * smallImageWidth / originalForm.Width); BWThreshold = BitmapUtils.GetMinMaxMiddleColorThreshold(smallForm); CreateSmallExpandedBW(smallForm); largeForm = BitmapUtils.Resize(originalForm, largeImageWidth, originalForm.Height * largeImageWidth / originalForm.Width); }
private void Load(string path) { //Create temp directory if (Directory.Exists("TempFontStorage")) { Directory.Delete("TempFontStorage", true); } Directory.CreateDirectory("TempFontStorage"); //Extract zip try { ZipFile.ExtractToDirectory(path, "TempFontStorage"); } catch (InvalidDataException e) { throw new FontLoadingException("Couldn't unpack zip", e); } //Load images string[] folders = Directory.GetDirectories("TempFontStorage"); foreach (string folder in folders) { FChar key = (FChar)Enum.Parse(typeof(FChar), Path.GetFileName(folder)); List <Bitmap> value = new List <Bitmap>(); string[] imagePaths = Directory.GetFiles(folder); foreach (string imagePath in imagePaths) { Bitmap loadedBitmap; using (Bitmap bitmap = BitmapUtils.LoadBitmap(imagePath)) { loadedBitmap = new Bitmap(bitmap); } value.Add(loadedBitmap); } images.Add(key, value); } //Load margins XElement file = XElement.Load("TempFontStorage/margins.xml"); var leftPairs = file.Descendants().Where((x) => x.Name == "leftMargins").First().Descendants().Where((elem) => elem.Name == "pair"); leftMargins = new Dictionary <FChar, List <double> >(); foreach (XElement pair in leftPairs) { FChar key = (FChar)Enum.Parse(typeof(FChar), pair.Attribute("key").Value); if (!leftMargins.ContainsKey(key)) { leftMargins.Add(key, new List <double>()); } leftMargins[key].AddRange(pair.Descendants().Select((item) => double.Parse(item.Attribute("value").Value, CultureInfo.InvariantCulture))); } var rightPairs = file.Descendants().Where((x) => x.Name == "rightMargins").First().Descendants().Where((elem) => elem.Name == "pair"); rightMargins = new Dictionary <FChar, List <double> >(); foreach (XElement pair in rightPairs) { FChar key = (FChar)Enum.Parse(typeof(FChar), pair.Attribute("key").Value); if (!rightMargins.ContainsKey(key)) { rightMargins.Add(key, new List <double>()); } rightMargins[key].AddRange(pair.Descendants().Select((item) => double.Parse(item.Attribute("value").Value, CultureInfo.InvariantCulture))); } //Delete temp directory if (Directory.Exists("TempFontStorage")) { Directory.Delete("TempFontStorage", true); } }