static Image LoadImage(ImageLoader loader, string fileName, ImageTagSet tagFilter) { var toolkit = Toolkit.CurrentEngine; if (toolkit == null) { throw new ToolkitNotInitializedException(); } var img = loader.LoadImage(fileName); var reqSize = toolkit.ImageBackendHandler.GetSize(img); var ext = GetExtension(fileName); var name = fileName.Substring(0, fileName.Length - ext.Length); var altImages = new List <Tuple <string, ImageTagSet, bool, object> > (); var tags = Context.RegisteredStyles; foreach (var r in loader.GetAlternativeFiles(fileName, name, ext)) { int scale; ImageTagSet fileTags; if (ParseImageHints(name, r, ext, out scale, out fileTags) && (tagFilter == null || tagFilter.Equals(fileTags))) { var rim = loader.LoadImage(r); if (rim != null) { altImages.Add(new Tuple <string, ImageTagSet, bool, object> (r, fileTags, scale > 1, rim)); } } } if (altImages.Count > 0) { altImages.Insert(0, new Tuple <string, ImageTagSet, bool, object> (fileName, ImageTagSet.Empty, false, img)); var list = new List <Tuple <Image, string[]> > (); foreach (var imageGroup in altImages.GroupBy(t => t.Item2)) { Image altImg; if (ext == ".9.png") { altImg = CreateComposedNinePatch(toolkit, imageGroup); } else { var ib = toolkit.ImageBackendHandler.CreateMultiResolutionImage(imageGroup.Select(i => i.Item4)); altImg = loader.WrapImage(fileName, imageGroup.Key, ib, reqSize); } list.Add(new Tuple <Image, string[]> (altImg, imageGroup.Key.AsArray)); } if (list.Count == 1) { return(list [0].Item1); } else { return(new ThemedImage(list, reqSize)); } } else { var res = loader.WrapImage(fileName, ImageTagSet.Empty, img, reqSize); if (ext == ".9.png") { res = new NinePatchImage(res.ToBitmap()); } return(res); } }
static Image LoadImage(ImageLoader loader, string fileName, ImageTagSet tagFilter) { var toolkit = Toolkit.CurrentEngine; if (toolkit == null) throw new ToolkitNotInitializedException (); var img = loader.LoadImage (fileName); var reqSize = toolkit.ImageBackendHandler.GetSize (img); var ext = GetExtension (fileName); var name = fileName.Substring (0, fileName.Length - ext.Length); var altImages = new List<Tuple<string,ImageTagSet,bool,object>> (); var tags = Context.RegisteredStyles; foreach (var r in loader.GetAlternativeFiles (fileName, name, ext)) { int scale; ImageTagSet fileTags; if (ParseImageHints (name, r, ext, out scale, out fileTags) && (tagFilter == null || tagFilter.Equals (fileTags))) { var rim = loader.LoadImage (r); if (rim != null) altImages.Add (new Tuple<string, ImageTagSet, bool, object> (r, fileTags, scale > 1, rim)); } } if (altImages.Count > 0) { altImages.Insert (0, new Tuple<string, ImageTagSet, bool, object> (fileName, ImageTagSet.Empty, false, img)); var list = new List<Tuple<Image,string[]>> (); foreach (var imageGroup in altImages.GroupBy (t => t.Item2)) { Image altImg; if (ext == ".9.png") altImg = CreateComposedNinePatch (toolkit, imageGroup); else { var ib = toolkit.ImageBackendHandler.CreateMultiResolutionImage (imageGroup.Select (i => i.Item4)); altImg = loader.WrapImage (fileName, imageGroup.Key, ib, reqSize); } list.Add (new Tuple<Image,string[]> (altImg, imageGroup.Key.AsArray)); } if (list.Count == 1) return list [0].Item1; else { return new ThemedImage (list, reqSize); } } else { var res = loader.WrapImage (fileName, ImageTagSet.Empty, img, reqSize); if (ext == ".9.png") res = new NinePatchImage (res.ToBitmap ()); return res; } }