コード例 #1
0
        DmFile ProcessFileCore(string file)
        {
            DmFile    model        = null;
            ImageInfo image        = null;
            Image     reducedImage = null;
            Image     previewImage = null;

            try {
                image = LoadImageInfo(file);
                if (image == null)
                {
                    return(model);                                //Error could not decode image!
                }
                previewImage = ResizeImageToPreview(image.image); //TODO create preview more correctly
                reducedImage = previewImage == null?ResizeImageToThumb(image.thumbImage) : ResizeImageToThumb(previewImage);

                FileInfo info = new FileInfo(file);
                model = CreateModel(info);
                string thumbPath   = ThumbsFolderManager.GetNextThumbPath(model.Id);
                string previewPath = ThumbsFolderManager.GetNextPreviewPath(model.Id);
                reducedImage.Save(thumbPath, ImageFormat.Jpeg);
                if (previewImage != null)
                {
                    previewImage.Save(previewPath, ImageFormat.Jpeg);
                    previewImage.Dispose();
                }
                model.MD5Hash         = MD5Helper.CalculateMD5(file);
                model.ThumbFileName   = thumbPath;
                model.PreviewFileName = previewPath;
                model.ThumbImage      = reducedImage;
                model.Width           = image.width;
                model.Height          = image.height;
                model.AspectRatio     = ((float)model.Width) / model.Height;
                model.Description     = image.description;
                model.ISO             = image.iso;
                model.ShutterSpeed    = image.shutter;
                model.Aperture        = image.aperture;
                model.Author          = image.artist;
                model.CameraModel     = image.model;
                model.CameraProducer  = image.model;
                model.FlashUsed       = image.flashUsed;
                model.FocalLength     = image.focalLength;
                model.Flip            = image.flip;

                CheckInitializeStorageVolumes();
                if (!CopyFile(file, model))
                {
                    StorageManager.OnCopyFileFailed();
                    FatalErrorOccured = true;
                    return(model);
                }

                model.FullPreviewFileName = model.FileNameWithoutExtension + "_Preview" + "." + model.Extension;
                //Image fullPreview = image.thumbImage;
                if (!StorageManager.SavePreviewFile(reducedImage, model.RelativePath, model.FullPreviewFileName))
                {
                    StorageManager.OnCopyFileFailed();
                    FatalErrorOccured = true;
                    return(model);
                }
                //fullPreview.Dispose();

                model.Dpi        = image.dpi;
                model.ColorDepth = image.colorDepth;
            } finally {
                if (image != null)
                {
                    image.thumbImage = null;
                    image.Dispose();
                }
            }
            return(model);
        }