public static ResourceFile Load(BinaryReader reader) { var resourceFile = new ResourceFile(); resourceFile.BitmapFileName = reader.ReadString(); resourceFile.HasTransparentColor = reader.ReadInt32() == 1; var r = reader.ReadByte(); var g = reader.ReadByte(); var b = reader.ReadByte(); var a = reader.ReadByte(); resourceFile.TransparentColor = Color.FromArgb(a, r, g, b); var layersCount = reader.ReadInt32(); for (var i = 0; i < layersCount; ++i) { reader.ReadString(); } resourceFile.Resources = new ObservableCollection<Resource>(); var resourcesCount = reader.ReadInt32(); for (var i = 0; i < resourcesCount; ++i) { var resource = Resource.Load(reader); resourceFile.Resources.Add(resource); } return resourceFile; }
public ResourceViewModel(Resource resource, ResourceFile resourceFile, string currentDirectory) { Resource = resource; ResourceFile = resourceFile; CurrentDirectory = currentDirectory; var bitmapFull = new BitmapImage(new Uri(CurrentDirectory + ResourceFile.BitmapFileName)); ResourceBitmap = bitmapFull.CreateCroppedBitmapResolutionInvariant(resource.Crop); }
public void LoadBitmap() { var dialog = new Microsoft.Win32.OpenFileDialog(); dialog.Filter = "Image files (*.jpg, *.png, *.bmp, *.tga, *.gif) | *.jpg; *.png; *.bmp; *.tga; *.gif"; var res = dialog.ShowDialog(); if (!res.Value) return; var uri = new Uri(dialog.FileName); ResourcesBitmap = new BitmapImage(uri); IsNoBitmapLoaded = false; CurrentDirectory = Path.GetDirectoryName(uri.LocalPath) + Path.AltDirectorySeparatorChar; ResourceFile = new ResourceFile { BitmapFileName = Path.GetFileName(uri.LocalPath), TransparentColor = Colors.Magenta, HasTransparentColor = true, Resources = new ObservableCollection<Resource>() }; }