コード例 #1
0
        public void CreatePreviews(string pathToFolder, PictureBox pictureBox, string previewFolderPath)
        {
            var converterProvider = new ConverterProvider();

            foreach (var filePath in Directory.EnumerateFiles(pathToFolder))
            {
                var image = GenerateImagePreviews(filePath, converterProvider, out long conversionTime);

                long   renderTime = 0;
                string status     = image != null ? "Ok" : "Error";
                long   resizeTime = 0;
                if (image != null)
                {
                    status = "Ok";
                    image  = ResizeImage(image, PreviewSize, out resizeTime);
                    ShowPreview(pictureBox, image, out renderTime);
                    SavePreview(image, filePath, previewFolderPath);
                    image.Dispose();
                }

                var totalTime = conversionTime + resizeTime + renderTime;
                var fileName  = Path.GetFileName(filePath);
                Log.LogInfo($"{fileName}, {conversionTime}, {renderTime}, {resizeTime}, {totalTime}, {status}");
            }
        }
コード例 #2
0
        public Image GenerateImagePreviews(string filePath, ConverterProvider converterProvider, out long conversionTime)
        {
            Image result = null;
            var   sw     = new Stopwatch();

            conversionTime = 0;
            try
            {
                sw.Start();
                var converter = converterProvider.GetConverter(filePath);
                if (converter != null)
                {
                    result = converter.Convert(filePath);
                }
                else
                {
                    Log.LogError($"Converter not found for {Path.GetFileName(filePath)}");
                }
                sw.Stop();
                conversionTime = sw.ElapsedMilliseconds;
            }
            catch (Exception ex)
            {
                Log.LogError($"{ex.Message} - {Path.GetFileName(filePath)}");
            }
            return(result);
        }