Пример #1
1
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);
            using (MagickImage image = new MagickImage(infile))
            {
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left = (int) (image.Width*prop.LiveviewSettings.HorizontalMin/100);
                    conf.Width = (image.Width*
                                  (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin)/100);
                    conf.Top = (image.Height*prop.LiveviewSettings.VerticalMin/100);
                    conf.Height = (image.Height*(prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin)/
                                   100);
                }
                if (conf.CropMargins)
                {
                    conf.Left = image.Width * conf.WidthProcent / 100;
                    conf.Width = image.Width - (conf.Left*2);
                    conf.Top = image.Height * conf.HeightProcent / 100;
                    conf.Height = image.Height - (conf.Top*2);
                }

                MagickGeometry geometry = new MagickGeometry();
                geometry.Width = conf.Width;
                geometry.Height = conf.Height;
                geometry.X = conf.Left;
                geometry.Y = conf.Top;
                image.Crop(geometry);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
Пример #2
0
        public string Execute(FileItem item, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);

            using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(item.FileName)))
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                                                            BitmapCreateOptions.PreservePixelFormat,
                                                            BitmapCacheOption.OnLoad);
                WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left  = (int)(writeableBitmap.PixelWidth * prop.LiveviewSettings.HorizontalMin / 100);
                    conf.Width =
                        (int)
                        (writeableBitmap.PixelWidth *
                         (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin) / 100);
                    conf.Top    = (int)(writeableBitmap.Height * prop.LiveviewSettings.VerticalMin / 100);
                    conf.Height =
                        (int)
                        (writeableBitmap.Height *
                         (prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin) / 100);
                }

                BitmapLoader.Save2Jpg(writeableBitmap.Crop(conf.Left, conf.Top, conf.Width, conf.Height), dest);
            }
            return(dest);
        }
Пример #3
0
        public string Execute(FileItem item,string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);
            using (var fileStream = new MemoryStream(File.ReadAllBytes(infile)))
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                    BitmapCreateOptions.PreservePixelFormat,
                    BitmapCacheOption.OnLoad);
                WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left = (int) (writeableBitmap.PixelWidth*prop.LiveviewSettings.HorizontalMin/100);
                    conf.Width =
                        (int)
                            (writeableBitmap.PixelWidth*
                             (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin)/100);
                    conf.Top = (int) (writeableBitmap.Height*prop.LiveviewSettings.VerticalMin/100);
                    conf.Height =
                        (int)
                            (writeableBitmap.Height*
                             (prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin)/100);
                }

                BitmapLoader.Save2Jpg(writeableBitmap.Crop(conf.Left,conf.Top,conf.Width,conf.Height), dest);
            }
            return dest;
        }
Пример #4
0
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);

            using (MagickImage image = new MagickImage(infile))
            {
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left  = (int)(image.Width * prop.LiveviewSettings.HorizontalMin / 100);
                    conf.Width = (image.Width *
                                  (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin) / 100);
                    conf.Top    = (image.Height * prop.LiveviewSettings.VerticalMin / 100);
                    conf.Height = (image.Height * (prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin) /
                                   100);
                }
                if (conf.CropMargins)
                {
                    conf.Left   = image.Width * conf.WidthProcent / 100;
                    conf.Width  = image.Width - (conf.Left * 2);
                    conf.Top    = image.Height * conf.HeightProcent / 100;
                    conf.Height = image.Height - (conf.Top * 2);
                }

                MagickGeometry geometry = new MagickGeometry();
                geometry.Width  = conf.Width;
                geometry.Height = conf.Height;
                geometry.X      = conf.Left;
                geometry.Y      = conf.Top;
                image.Crop(geometry);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return(dest);
        }