Esempio n. 1
0
        public override bool Process(ImageWI iwi)
        {
            try {
                FIBITMAP shrinkedDib;
                FileInfo ftmp;
                switch (this.WorkingStyle)
                {
                case TASKWORKINGSTYLE.STRAIGHT:
                    // do not save. just shrink
                    // create shrinked image in memory
                    shrinkedDib = ImageWorker.GetShrinkedDIB(iwi.ImageHandle, this.calcNewSize(iwi));
                    // cleanup old current handle
                    ImageWorker.CleanUpResources(iwi.ImageHandle);
                    // set shrinked version the new current
                    iwi.ImageHandle = shrinkedDib;
                    break;

                case TASKWORKINGSTYLE.COPYOUTPUT:
                    ftmp = new FileInfo(iwi.CurrentFile.AugmentFilename(this.NameExtension));
                    // save shrinked version of image to file
                    shrinkedDib = ImageWorker.GetShrinkedDIB(iwi.ImageHandle, this.calcNewSize(iwi));
                    ImageWorker.SaveJPGImageHandle(shrinkedDib, ftmp);
                    // now we have the original and the shrinked version on disk
                    // check which version should be handed over to the next task
                    // after this the smaller image is the new current
                    ImageWorker.CleanUpResources(iwi.ImageHandle);
                    // set it the new current
                    iwi.ImageHandle = shrinkedDib;
                    iwi.CurrentFile = ftmp;
                    break;

                case TASKWORKINGSTYLE.COPYINPUT:
                    ftmp = new FileInfo(iwi.CurrentFile.AugmentFilename(this.NameExtension));
                    // save shrinked version of image to file
                    shrinkedDib = ImageWorker.GetShrinkedDIB(iwi.ImageHandle, this.calcNewSize(iwi));
                    ImageWorker.SaveJPGImageHandle(shrinkedDib, ftmp);
                    // now we have the original and the shrinked version on disk
                    // check which version should be handed over to the next task
                    // handle for shrinked version is not needed anymore
                    ImageWorker.CleanUpResources(shrinkedDib);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            } catch (Exception ex) {
                logger.ErrorException(string.Format("error while shrinking file {0}", iwi.CurrentFile.Name), ex);
            }
            return(true);
        }