示例#1
0
        public static void Main(string[] args)
        {
            if (args.Length < 1 || args.Length > 2)
            {
                Console.WriteLine("Parameters not matching!");
                Console.WriteLine("Usage: IcoEncoderCLI.exe <SourceImagePath> [<OutputPath>]");
                return;
            }

            string sourceFilePath = Path.GetFullPath(args[0]);
            string icoFilePath;

            if (args.Length >= 2)
            {
                icoFilePath = Path.GetFullPath(args[1]);
            }
            else
            {
                string directoryPath = Path.GetDirectoryName(sourceFilePath);
                icoFilePath = Path.Combine(directoryPath, Path.GetFileNameWithoutExtension(sourceFilePath) + ".ico");
            }

            using var icoStream = File.OpenWrite(icoFilePath);
            var icoEncoder = new IcoEncoder(icoStream);

            EncodeImageForResolution(icoEncoder, new WICSize(256, 256), sourceFilePath);

            icoEncoder.Commit();
        }
示例#2
0
        public void Test(string fileName, int width, int height)
        {
            string pngFilePath = TestUtil.GetResourceFilePath(fileName);

            using var pngStream = File.OpenRead(pngFilePath);

            string icoFilePath = TestUtil.GetTestFilePath(Path.GetFileName(pngFilePath) + ".ico");

            using (var icoStream = File.OpenWrite(icoFilePath))
            {
                var icoEncoder = new IcoEncoder(icoStream);
                icoEncoder.AddImage(new ImageInfo(pngStream, (byte)width, (byte)height, 0, 32));
                icoEncoder.Commit();
            }

            ValidateIcoFile(icoFilePath, width, height);
        }