public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            if (args.Length < 1)
            {
                Console.WriteLine("Nothing to do");
            }

            var fileInfo = new System.IO.FileInfo(args[0]);

            if (!fileInfo.Exists)
            {
                Console.WriteLine("Nothing to do! File does not exists");
                return;
            }


            CodeBuilder codeBuilder;
            string      code;

            if (fileInfo.Extension.Equals(".gif", StringComparison.InvariantCultureIgnoreCase))
            {
                //multiple images
                using (var gif = AnimatedGif.LoadFrom(fileInfo.FullName))
                {
                    Console.WriteLine(gif.FrameCount);
                    var frames = gif.Select(x => new LedFrame(x)).ToList();
                    Console.WriteLine(frames.Count());

                    codeBuilder = new CodeBuilder(frames);
                }
                code = codeBuilder.GenerateGif();
            }
            //Single image
            else
            {
                var img = Image.FromFile(fileInfo.Name) as Bitmap;

                codeBuilder = new CodeBuilder(ImageReader.Read(img));
                code        = codeBuilder.GenerateSimpleImage();
            }



            System.IO.File.WriteAllText($"{fileInfo.Name}.ino", code.ToString());
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            // Declare the text that will be put onto the image
            const string WatermarkText = "Watermark Test";

            // Create the colour for our watermark, 75% opacity white
            var colour = Color.FromArgb((int)(byte.MaxValue * 0.75), Color.White);

            // The brush the text will be drawn with
            var brush = new SolidBrush(colour);

            // Create a font for our watermark.
            using (var font = new Font(FontFamily.GenericSerif, 14, FontStyle.Regular, GraphicsUnit.Point))
                using (var gif = AnimatedGif.LoadFrom("..\\..\\Assets\\Pumpjack.gif"))
                {
                    // Iterate over each frame
                    foreach (var frame in gif)
                    {
                        // Construct a Graphics object for the current frame image
                        using (var graphics = Graphics.FromImage(frame.Image))
                        {
                            // Measure the string for positioning
                            var textSize = graphics.MeasureString(WatermarkText, font);

                            // Position the text in the lower-right corner, with a 10 pixel margin on the horizonatl axis
                            var textLocation = new PointF
                            {
                                X = frame.Image.Width - textSize.Width - 10,
                                Y = frame.Image.Height - textSize.Height
                            };

                            // Draw the string
                            graphics.DrawString(WatermarkText, font, brush, textLocation);

                            // Flush any pending operations
                            graphics.Flush();
                        }
                    }

                    // Write the newly watermarked image back to disk
                    gif.Save("Watermarked.gif");
                }
        }
        static bool Convert(string srcPath, string destPath, int destFPS)
        {
            var result = false;

            try
            {
                using (var srcGif = AnimatedGif.LoadFrom(srcPath))
                {
                    var fixedGifOffset = TimeSpan.FromMilliseconds(1000 / destFPS);
                    var crntSrcOffset  = new TimeSpan();
                    var crntDestOffset = new TimeSpan();

                    using (var destGif = new AnimatedGif())
                    {
                        foreach (var srcFrame in srcGif)
                        {
                            crntSrcOffset += srcFrame.Delay;

                            do
                            {
                                crntDestOffset += fixedGifOffset;

                                var destFrame = (Image)srcFrame.Image.Clone();
                                destGif.AddFrame(destFrame, fixedGifOffset);
                            }while (crntSrcOffset > crntDestOffset);
                        }

                        destGif.Save(destPath);

                        Console.WriteLine($"Successfully converted \"{Path.GetFileName(srcPath)}\" to \"{Path.GetFileName(destPath)}\". New file contains {destGif.FrameCount} frames.");

                        result = true;
                    }
                }
            }
            catch (Exception) { }

            return(result);
        }