public override int GetHashCode() { unchecked { var hashCode = _types != null?_types.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (SliceKey != null ? SliceKey.GetHashCode() : 0); return(hashCode); } }
public Image GetImage(string tileKeyContentPath, int dimension, Rectangle?sliceRectangle, BitmapSource tileSource) { var key = new SliceKey(tileKeyContentPath, sliceRectangle); if (ImageFactory.TryGetValue(key, out var image)) { return(image); } var tile = new Image { Height = dimension, Width = dimension, Source = tileSource }; ImageFactory.Add(key, tile); return(tile); }
public BitmapSource GetBitmapSource(string bitmapSourcePath, Rectangle?area = null) { try { if (string.IsNullOrEmpty(bitmapSourcePath)) { return(null); } var key = new SliceKey(bitmapSourcePath, area); if (BitmapSourceFactory.TryGetValue(key, out var croppedBitmapSource)) { return(croppedBitmapSource); } if (area.HasValue) { var nonCroppedkey = new SliceKey(bitmapSourcePath, null); if (!BitmapSourceFactory.TryGetValue(nonCroppedkey, out var bitmapSource)) { bitmapSource = BitmapSourceFromPath(bitmapSourcePath); BitmapSourceFactory.Add(nonCroppedkey, bitmapSource); } var croppedBitMap = new CroppedBitmap(bitmapSource, new Int32Rect(area.Value.X, area.Value.Y, area.Value.Width, area.Value.Height)); BitmapSourceFactory.Add(key, croppedBitMap); return(croppedBitMap); } else { var bitMapSource = BitmapSourceFromPath(bitmapSourcePath); BitmapSourceFactory.Add(key, bitMapSource); return(bitMapSource); } } catch (Exception e) { throw new BitmapLoadException($"Could not load bitmap from path with rect {area.ToString()}: {bitmapSourcePath}", e); } }