private static string MapFilePath(string mapName, FormatSize size) { if (String.IsNullOrEmpty(mapName)) { return(String.Empty); } // Relative path to map image string filename = @".\images\" + mapName.Trim(); // Append size modifer switch (size) { case FormatSize.Small_128: filename += "_128x128"; break; default: case FormatSize.Medium_256: filename += "_256x256"; break; case FormatSize.Original_992: break; } // Append file extention filename += ".jpg"; return(filename); }
internal static BitmapImage GetMapImage(string mapName, FormatSize size = FormatSize.Medium_256) { if (String.IsNullOrEmpty(mapName)) { logger.Warn("Map name is null or empty"); return(null); } // Try to get cached image if (imageCache.TryGetValue(mapName, out var img)) { return(img); } // Get image path var path = MapFilePath(mapName, size); // Check for invalid path if (String.IsNullOrEmpty(path) || !File.Exists(path)) { logger.Error("Map image not found. Path: \"" + path + "\""); return(null); } // Open filestream to image at path using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // Initialize BitmapImage img = new BitmapImage(); img.BeginInit(); img.StreamSource = fs; img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); // Add image to cache imageCache.Add(mapName, img); return(img); }
public static Uri GetMapImageUri(string mapName, FormatSize size = FormatSize.Medium_256) { if (String.IsNullOrEmpty(mapName)) { return(null); } string filename = mapName.Trim(); switch (size) { case FormatSize.Small_128: filename += "_128x128"; break; default: case FormatSize.Medium_256: filename += "_256x256"; break; case FormatSize.Original_992: break; } var uri = new Uri(Environment.CurrentDirectory + "//images//" + filename + ".jpg", UriKind.Absolute); return(File.Exists(uri.AbsolutePath) ? uri : null); }
public IndexBuffer(Device device, int IndicesCount, string bufferName, int AutoResizePerc = 0, ResourceUsage usage = ResourceUsage.Default) { _indicesCount = 0; _bufferCount = IndicesCount + (IndicesCount * _autoResizePerc / 100); TypeCode typeCode = Type.GetTypeCode(typeof(dataType)); switch (typeCode) { case TypeCode.UInt16: _indexFormat = Format.R16_UInt; break; case TypeCode.UInt32: _indexFormat = Format.R32_UInt; break; default: throw new Exception("Index type not supported for " + typeCode.ToString()); } _autoResizePerc = AutoResizePerc; _bufferName = bufferName; _device = device; _indexStride = FormatSize.GetFormatSize(_indexFormat); //Create the buffer description object _description = new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = usage == ResourceUsage.Default || usage == ResourceUsage.Immutable ? CpuAccessFlags.None : CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = _bufferCount * _indexStride, Usage = usage }; }