public void CopyTo(ThumbnailMonitorContext target) {
     target.MonitorTargetPath = this.MonitorTargetPath;
     target.ThumbnailSize = this.ThumbnailSize;
     target.KeepOriginalSize = this.KeepOriginalSize;
     target.KeepAspect = this.KeepAspect;
     target.HighQuality = this.HighQuality;
     target.OutputPath = this.OutputPath;
     target.PostResizeMethod = this.PostResizeMethod;
     target.BackgroundColorARGB = this.BackgroundColorARGB;
     target.OutputFilenameFormat = this.OutputFilenameFormat;
     target.FilenameNextNumber = this.FilenameNextNumber;
     target.OutputFileExtension = this.OutputFileExtension;
     target.LastCheckFilePath = this.LastCheckFilePath;
     target.TargetLastWriteTime = this.TargetLastWriteTime;
 }
Пример #2
0
        void saveThumbnail(ThumbnailMonitorContext context) {
            // サムネイル取得、保存
            string inputPath = context.MonitorTargetPath;
            string outputPath = context.AbsoluteOutputPath;
            string extension = context.OutputFileExtension;
            Size size = context.ThumbnailSize;
            PostResizeMethod resizeMethod = context.PostResizeMethod;

            FileInfo fileInfo = new FileInfo(inputPath);

            string savePath = context.GenerateNextSavePath(fileInfo.LastWriteTime);
            var format = Syego.Common.Miscs.GetImageFormatFromFileExtension(extension);

            updateState("サムネイルを取得しています...");
            Bitmap outputBitmap;
            using (Image rawImage = ThumbnailExtractor.GetThumbnailImage(
                inputPath,
                context.ThumbnailSize,
                context.KeepOriginalSize,
                context.KeepAspect,
                context.HighQuality)) {

                Size outputSize;
                Rectangle renderRect;
                switch (resizeMethod) {
                    case PostResizeMethod.NoResize:
                        outputSize = rawImage.Size;
                        renderRect = new Rectangle(Point.Empty, outputSize);
                        break;
                    case PostResizeMethod.Inscribe:
                        outputSize = Syego.Common.Miscs.GetInscribedRectSize(context.ThumbnailSize, rawImage.Size);
                        renderRect = new Rectangle(Point.Empty, outputSize);
                        break;
                    case PostResizeMethod.InscribeAndAddMargin:
                        outputSize = context.ThumbnailSize;
                        renderRect = Syego.Common.Miscs.GetInternalContactRect(
                            new Rectangle(Point.Empty, context.ThumbnailSize), rawImage.Size);
                        break;
                    case PostResizeMethod.ForceResize:
                        outputSize = context.ThumbnailSize;
                        renderRect = new Rectangle(Point.Empty, outputSize);
                        break;
                    default:
                        throw new NotImplementedException();
                }

                outputBitmap = new Bitmap(outputSize.Width, outputSize.Height, PixelFormat.Format32bppArgb);
                using (Graphics g = Graphics.FromImage(outputBitmap)) {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                    g.Clear(Color.FromArgb(context.BackgroundColorARGB));
                    g.DrawImage(rawImage, renderRect, new Rectangle(0, 0, rawImage.Width, rawImage.Height), GraphicsUnit.Pixel);
                }
            }
            outputBitmap.Save(savePath, format);
            updateThumbnailImage(outputBitmap);
            updateState("サムネイルを保存しました : " + Path.GetFileName(savePath) + " (" + outputBitmap.Width + "x" + outputBitmap.Height + ")");

            context.LastCheckFilePath = fileInfo.FullName;
            context.TargetLastWriteTime = fileInfo.LastWriteTime;
            return;
        }
Пример #3
0
        void checkThumbnail(ThumbnailMonitorContext context) {
            _lastCheckTime = DateTime.Now;

            // ファイルが存在しない場合は停止
            if (!File.Exists(context.MonitorTargetPath)) {
                stopInternally();
                updateState("監視対象ファイルを見失ったため監視を停止しました", true);
                return;
            }

            FileInfo fileInfo = new FileInfo(context.MonitorTargetPath);

            // ファイルに更新が無い場合は無視
            if ((fileInfo.FullName == context.LastCheckFilePath) &&
                (fileInfo.LastWriteTime == context.TargetLastWriteTime)) {

                updateState("前回からの変更は見つかりませんでした");
                return;
            }

            saveThumbnail(context);
        }