Example #1
0
        private Task TakeScreenshot(string path, SupportedImageFormat format)
        {
            var source = new TaskCompletionSource <Unit>();

            if (this.targetCanvas == null && !this.AssociatedObject.TryGetKanColleCanvas(out this.targetCanvas))
            {
                source.SetException(new Exception("艦これの Canvas 要素が見つかりません。"));
                return(source.Task);
            }

            var request = new ScreenshotRequest(path, source);
            var script  = $@"
(async function()
{{
	await CefSharp.BindObjectAsync('{request.Id}');

	var canvas = document.querySelector('canvas');
	requestAnimationFrame(() =>
	{{
		var dataUrl = canvas.toDataURL('{format.ToMimeType()}');
		{request.Id}.complete(dataUrl);
	}});
}})();
";

            this.AssociatedObject.JavascriptObjectRepository.Register(request.Id, request, true);
            this.targetCanvas.ExecuteJavaScriptAsync(script);

            return(source.Task);
        }
Example #2
0
        public static string CreateScreenshotFilePath(SupportedImageFormat format)
        {
            var filePath = Path.Combine(
                ScreenshotSettings.Destination,
                $"KanColle-{DateTimeOffset.Now.LocalDateTime:yyMMdd-HHmmssff}");

            return(Path.ChangeExtension(filePath, format.ToExtension()));
        }
Example #3
0
        // Constructor
        public FileImage(int tileindex, string filepathname)
        {
            // Initialize
            this.filepathname   = filepathname;
            this.probableformat = SupportedImageFormat.UNKNOWN;
            this.tileindex      = tileindex;

            // We have no destructor
            GC.SuppressFinalize(this);
        }
        public static string ToMimeType(this SupportedImageFormat format)
        {
            switch (format)
            {
            case SupportedImageFormat.Png:
                return("image/png");

            case SupportedImageFormat.Jpeg:
                return("image/jpeg");

            default:
                return("");
            }
        }
        public static string ToExtension(this SupportedImageFormat format)
        {
            switch (format)
            {
            case SupportedImageFormat.Png:
                return(".png");

            case SupportedImageFormat.Jpeg:
                return(".jpg");

            default:
                return("");
            }
        }
Example #6
0
        public static string CreateScreenshotFilePath(SupportedImageFormat format)
        {
            var directory = Settings.ScreenshotSettings.Destination;

            var filePath = Path.Combine(
                directory,
                $"KanColle-{DateTimeOffset.Now.LocalDateTime.ToString("yyMMdd-HHmmssff")}"
                );

            filePath = Path.ChangeExtension(
                filePath,
                Settings.ScreenshotSettings.Format == SupportedImageFormat.Png ? ".png" : ".jpg"
                );

            return(Path.ChangeExtension(filePath, format.ToExtension()));
        }
Example #7
0
        // This check image data and returns the appropriate image reader
        public static IImageReader GetImageReader(Stream data, SupportedImageFormat guessformat, Playpal palette)
        {
            //BinaryReader bindata = new BinaryReader(data);

            // This can ONLY be an ART file, right?
            if (guessformat == SupportedImageFormat.ART && data.Length > 0)
            {
                return(new ARTImageReader(palette));
            }

            // First check the formats that provide the means to 'ensure' that
            // it actually is that format. Then guess the Doom image format.

            // Data long enough to check for signatures?

            /*if(data.Length > 10)
             * {
             *      // Check for PNG signature
             *      data.Seek(0, SeekOrigin.Begin);
             *      if(CheckSignature(data, PNG_SIGNATURE)) return new FileImageReader();
             *
             *      // Check for DDS signature
             *      data.Seek(0, SeekOrigin.Begin);
             *      if(CheckSignature(data, DDS_SIGNATURE)) return new FileImageReader();
             *
             *      // Check for GIF signature
             *      data.Seek(0, SeekOrigin.Begin);
             *      if(CheckSignature(data, GIF_SIGNATURE)) return new FileImageReader();
             *
             *      // Check for BMP signature
             *      data.Seek(0, SeekOrigin.Begin);
             *      if(CheckSignature(data, BMP_SIGNATURE))
             *      {
             *              // Check if data size matches the size specified in the data
             *              if(bindata.ReadUInt32() <= data.Length) return new FileImageReader();
             *      }
             * }*/

            // Format not supported
            return(new UnknownImageReader());
        }
Example #8
0
        public static void Main(string[] args)
        {
            var friendlyName = AppDomain.CurrentDomain.FriendlyName;
            var newLine      = Environment.NewLine;
            var setter       = new OptionSetter();

            String fileName = null, outputFileName = null, payload = null;

            QRCodeGenerator.ECCLevel eccLevel    = QRCodeGenerator.ECCLevel.L;
            SupportedImageFormat     imageFormat = SupportedImageFormat.Png;
            int    pixelsPerModule               = 20;
            string foregroundColor               = "#000000";
            string backgroundColor               = "#FFFFFF";


            var showHelp = false;

            var optionSet = new OptionSet {
                { "e|ecc-level=",
                  "error correction level",
                  value => eccLevel = setter.GetECCLevel(value) },
                { "f|output-format=",
                  "Image format for outputfile. Possible values: png, jpg, gif, bmp, tiff, svg (default: png)",
                  value => { Enum.TryParse(value, true, out imageFormat); } },
                {
                    "i|in=",
                    "input file | alternative to parameter -p",
                    value => fileName = value
                },
                {
                    "p|payload=",
                    "payload string | alternative to parameter -i",
                    value => payload = value
                },
                {
                    "o|out=",
                    "output file",
                    value => outputFileName = value
                },
                { "s|pixel=",
                  "pixels per module",
                  value => {
                      if (int.TryParse(value, out pixelsPerModule))
                      {
                          if (pixelsPerModule < 1)
                          {
                              pixelsPerModule = 20;
                          }
                      }
                      else
                      {
                          pixelsPerModule = 20;
                      }
                  } },
                { "l|background=",
                  "background color",
                  value => backgroundColor = value },
                { "d|foreground=",
                  "foreground color",
                  value => foregroundColor = value },
                { "h|help",
                  "show this message and exit.",
                  value => showHelp = value != null }
            };

            try
            {
                optionSet.Parse(args);

                if (showHelp)
                {
                    ShowHelp(optionSet);
                }

                string text = null;
                if (fileName != null)
                {
                    var fileInfo = new FileInfo(fileName);
                    if (fileInfo.Exists)
                    {
                        text = GetTextFromFile(fileInfo);
                    }
                    else
                    {
                        Console.WriteLine($"{friendlyName}: {fileName}: No such file or directory");
                    }
                }
                else if (payload != null)
                {
                    text = payload;
                }
                else
                {
                    var stdin = Console.OpenStandardInput();

                    text = GetTextFromStream(stdin);
                }

                if (text != null)
                {
                    GenerateQRCode(payload, eccLevel, outputFileName, imageFormat, pixelsPerModule, foregroundColor, backgroundColor);
                }
            }
            catch (Exception oe)
            {
                Console.Error.WriteLine(
                    $"{friendlyName}:{newLine}{oe.GetType().FullName}{newLine}{oe.Message}{newLine}{oe.StackTrace}{newLine}Try '{friendlyName} --help' for more information");
                Environment.Exit(-1);
            }
        }
Example #9
0
        private static void GenerateQRCode(string payloadString, QRCodeGenerator.ECCLevel eccLevel, string outputFileName, SupportedImageFormat imgFormat, int pixelsPerModule, string foreground, string background)
        {
            using (var generator = new QRCodeGenerator())
            {
                using (var data = generator.CreateQrCode(payloadString, eccLevel))
                {
                    switch (imgFormat)
                    {
                    case SupportedImageFormat.Png:
                    case SupportedImageFormat.Jpg:
                    case SupportedImageFormat.Gif:
                    case SupportedImageFormat.Bmp:
                    case SupportedImageFormat.Tiff:
                        using (var code = new QRCode(data))
                        {
                            using (var bitmap = code.GetGraphic(pixelsPerModule, foreground, background, true))
                            {
                                var actualFormat = new OptionSetter().GetImageFormat(imgFormat.ToString());
                                bitmap.Save(outputFileName, actualFormat);
                            }
                        }
                        break;

                    case SupportedImageFormat.Svg:
                        using (var code = new SvgQRCode(data))
                        {
                            var test = code.GetGraphic(pixelsPerModule, foreground, background, true);
                            using (var f = File.CreateText(outputFileName))
                            {
                                f.Write(test);
                                f.Flush();
                            }
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(imgFormat), imgFormat, null);
                    }
                }
            }
        }