private static ImageSource GetAsImageSource(SaintCoinach.Imaging.ImageFile file) { if (file == null) { return(null); } var key = file.Path; WeakReference <ImageSource> targetRef; ImageSource target; if (!_SourceCache.TryGetValue(key, out targetRef) || !targetRef.TryGetTarget(out target)) { target = CreateSource(file); if (targetRef == null) { _SourceCache.Add(key, new WeakReference <ImageSource>(target)); } else { targetRef.SetTarget(target); } } return(target); }
private static ImageSource CreateSource(SaintCoinach.Imaging.ImageFile file) { var argb = SaintCoinach.Imaging.ImageConverter.GetA8R8G8B8(file); return(System.Windows.Media.Imaging.BitmapSource.Create( file.Width, file.Height, 96, 96, PixelFormats.Bgra32, null, argb, file.Width * 4)); }
public string Write(SaintCoinach.Imaging.ImageFile sImageFile) { if (sImageFile == null) { return(null); } var image = sImageFile.GetImage(); using (var stream = new MemoryStream()) { image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); return(Write(".png", stream.ToArray())); } }
private static SaintCoinach.Imaging.ImageFile GetImageOfType(SaintCoinach.Imaging.ImageFile original, string type) { if (string.IsNullOrWhiteSpace(type)) { return(original); } if (!original.Path.StartsWith("ui/icon/")) { return(original); // XXX: Exception instead? } var dirPath = original.Path.Substring(0, "ui/icon/000000/".Length); var targetPath = string.Format("{0}{1}/{2}", dirPath, type, original.Path.Split('/').Last()); SaintCoinach.IO.File typeFile; if (original.Pack.Collection.TryGetFile(targetPath, out typeFile)) { return((SaintCoinach.Imaging.ImageFile)typeFile); } return(original); }
public static int GetIconId(SaintCoinach.Imaging.ImageFile icon) { return(int.Parse(System.IO.Path.GetFileNameWithoutExtension(icon.Path))); }
public static void SetImage(DependencyObject o, SaintCoinach.Imaging.ImageFile v) { o.SetValue(ImageProperty, v); }