public IcnsIcon AddImage(Image image, IcnsType type) { var ret = new IcnsIcon(image, type); Icons.Add(ret); return(ret); }
public IcnsIcon AddImage(string filename, IcnsType type) { using (var image = Image.FromFile(filename)) { var newImage = (Image)image.Clone(); var ret = new IcnsIcon(newImage, type); Icons.Add(ret); return(ret); } }
public IcnsFile(string filename) : this() { using (var fs = File.OpenRead(filename)) { using (var reader = new BinaryReaderBigEndian(fs)) { var magic = Encoding.ASCII.GetString(reader.ReadBytes(4)); if (magic != "icns") { throw new FileLoadException("File is not an icns file.", filename); } uint fileSize = reader.ReadUInt32_BigEndian(); while (fs.Position < fs.Length) { var osType = Encoding.ASCII.GetString(reader.ReadBytes(4)); var osSize = reader.ReadInt32_BigEndian() - 8; if (osType == "TOC ") { #if DEBUG Console.WriteLine("There are {0} icons in the table of contents", osSize / 8); #endif fs.Seek(osSize, SeekOrigin.Current); continue; } if (osType == "icnV") { float version = reader.ReadSingle_BigEndian(); #if DEBUG Console.WriteLine("This icon was made with Icon Composer.app version {0}", version); #endif continue; } if (osType == "name") { #if DEBUG Console.WriteLine("Encountered a 'name' OSType with size {0}", osSize); #endif fs.Seek(osSize, SeekOrigin.Current); continue; } if (osType == "info") { #if DEBUG Console.WriteLine("Encountered an 'info' binary plist OSType with size {0}", osSize); #endif fs.Seek(osSize, SeekOrigin.Current); continue; } IcnsType iconType; try { iconType = GetTypeForIdent(osType); } catch { fs.Seek(osSize, SeekOrigin.Current); #if DEBUG Console.WriteLine("WARNING: Unsupported OSType: '{0}' with size {1}", osType, osSize); #endif Icons.Add(new IcnsIcon(IcnsType.unsupported, osSize)); continue; } #if DEBUG var iconSize = GetSizeForType(iconType); Console.WriteLine("Icon size: {0} x {1}", iconSize.Width, iconSize.Height); #endif var newIcon = new IcnsIcon(iconType, osSize); newIcon.Read(reader); Icons.Add(newIcon); } } } }