示例#1
0
        private static List <string> ApplyBlurEffectTextBox(Models.PowerPointSlide slide, string imageFile, PowerPoint.Shape textBox)
        {
            List <string> shapeNames = new List <string>();

            shapeNames.Add(textBox.Name);

            textBox.ZOrder(Office.MsoZOrderCmd.msoBringToFront);
            textBox.Fill.Visible = Office.MsoTriState.msoFalse;
            textBox.Line.Visible = Office.MsoTriState.msoFalse;

            PowerPoint.Shape blurShape = slide.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, textBox.Left, textBox.Top, textBox.Width,
                                                               textBox.Height);
            blurShape.Rotation = textBox.Rotation;
            Utils.ShapeUtil.MoveZToJustBehind(blurShape, textBox);
            CropToShape.FillInShapeWithImage(slide, imageFile, blurShape, isInPlace: true);
            shapeNames.Add(blurShape.Name);

            if (EffectsLabSettings.IsTintSelected)
            {
                PowerPoint.Shape overlayShape = GenerateOverlayShape(slide, blurShape);
                shapeNames.Add(overlayShape.Name);
            }

            // cannot group placeholders
            if (textBox.Type != Office.MsoShapeType.msoPlaceholder)
            {
                PowerPoint.ShapeRange subRange     = slide.Shapes.Range(shapeNames.ToArray());
                PowerPoint.Shape      groupedShape = subRange.Group();
                shapeNames.Clear();
                shapeNames.Add(groupedShape.Name);
            }

            return(shapeNames);
        }
示例#2
0
        private void SaveCropButton_OnClick(object sender, RoutedEventArgs e)
        {
            var rect        = _croppingAdorner.ClippingRectangle;
            var xRatio      = rect.X / ImageHolder.ActualWidth;
            var yRatio      = rect.Y / ImageHolder.ActualHeight;
            var widthRatio  = rect.Width / ImageHolder.ActualWidth;
            var heightRatio = rect.Height / ImageHolder.ActualHeight;

            Rect = rect;

            var originalImg = (Bitmap)Bitmap.FromFile(CropResult);
            var result      = CropToShape.KiCut(originalImg,
                                                (float)xRatio * originalImg.Width,
                                                (float)yRatio * originalImg.Height,
                                                (float)widthRatio * originalImg.Width,
                                                (float)heightRatio * originalImg.Height);

            CropResult = StoragePath.GetPath("crop-"
                                             + DateTime.Now.GetHashCode() + "-"
                                             + Guid.NewGuid().ToString().Substring(0, 7));
            result.Save(CropResult);

            CropResultThumbnail = ImageUtil.GetThumbnailFromFullSizeImg(CropResult);
            IsCropped           = true;

            Close();
        }
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();

            IMessageService     cropLabMessageService = MessageServiceFactory.GetCropLabMessageService();
            CropLabErrorHandler errorHandler          = CropLabErrorHandler.InitializeErrorHandler(cropLabMessageService);

            if (!ShapeUtil.IsSelectionShape(this.GetCurrentSelection()))
            {
                HandleInvalidSelectionError(CropLabErrorHandler.ErrorCodeSelectionIsInvalid, FeatureName, CropLabErrorHandler.SelectionTypeShape, 1, errorHandler);
                return;
            }
            ShapeRange shapeRange = this.GetCurrentSelection().ShapeRange;

            if (shapeRange.Count < 1)
            {
                HandleInvalidSelectionError(CropLabErrorHandler.ErrorCodeSelectionIsInvalid, FeatureName, CropLabErrorHandler.SelectionTypeShape, 1, errorHandler);
                return;
            }
            if (!ShapeUtil.IsAllShape(shapeRange))
            {
                HandleErrorCode(CropLabErrorHandler.ErrorCodeSelectionMustBeShape, FeatureName, errorHandler);
                return;
            }
            try
            {
                CropToShape.Crop(this.GetCurrentSlide(), this.GetCurrentSelection());
            }
            catch (CropLabException)
            {
                HandleErrorCode(CropLabErrorHandler.ErrorCodeUndefined, FeatureName, errorHandler);
            }
        }
        private string CropAndSaveImageFromFile(string image, double xRatio, double yRatio, double widthRatio, double heightRatio)
        {
            Bitmap originalImg = (Bitmap)Bitmap.FromFile(image);
            Bitmap result      = CropToShape.KiCut(originalImg,
                                                   (float)xRatio * originalImg.Width,
                                                   (float)yRatio * originalImg.Height,
                                                   (float)widthRatio * originalImg.Width,
                                                   (float)heightRatio * originalImg.Height);
            string croppedImage = StoragePath.GetPath("crop-"
                                                      + DateTime.Now.GetHashCode() + "-"
                                                      + Guid.NewGuid().ToString().Substring(0, 7));

            result.Save(croppedImage);
            return(croppedImage);
        }
        //Stores slide-size crop of the current slide as a global variable
        private void AddZoomSlideCroppedPicture(float magnifyRatio = 1.0f)
        {
            PowerPointSlide zoomSlideCopy = this.Duplicate();

            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(zoomSlideCopy.Index);

            PowerPoint.Shape cropShape = zoomSlideCopy.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 0, 0, PowerPointPresentation.Current.SlideWidth - 0.01f, PowerPointPresentation.Current.SlideHeight - 0.01f);
            cropShape.Select();
            PowerPoint.Selection sel          = Globals.ThisAddIn.Application.ActiveWindow.Selection;
            PowerPoint.Shape     croppedShape = CropToShape.Crop(zoomSlideCopy, sel, magnifyRatio: magnifyRatio);
            croppedShape.Cut();

            zoomSlideCroppedShapes      = _slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
            zoomSlideCroppedShapes.Name = "PPTLabsMagnifyAreaGroup" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
            Utils.ShapeUtil.FitShapeToSlide(ref zoomSlideCroppedShapes);
            zoomSlideCopy.Delete();
        }
示例#6
0
        //Stores slide-size crop of the current slide as a global variable
        private void AddZoomSlideCroppedPicture(float magnifyRatio = 1.0f)
        {
            PowerPointSlide zoomSlideCopy = this.Duplicate();

            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(zoomSlideCopy.Index);

            PowerPoint.Shape cropShape = zoomSlideCopy.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 0, 0, PowerPointPresentation.Current.SlideWidth - 0.01f, PowerPointPresentation.Current.SlideHeight - 0.01f);
            cropShape.Select();
            PowerPoint.Selection sel          = Globals.ThisAddIn.Application.ActiveWindow.Selection;
            PowerPoint.Shape     croppedShape = CropToShape.Crop(zoomSlideCopy, sel, magnifyRatio: magnifyRatio);
            try
            {
                string tempFilePath = FileDir.GetTemporaryPngFilePath();
                Utils.GraphicsUtil.ExportShape(croppedShape, tempFilePath);
                zoomSlideCroppedShapes = _slide.Shapes.AddPicture2(tempFilePath,
                                                                   Office.MsoTriState.msoFalse,
                                                                   Office.MsoTriState.msoTrue,
                                                                   0,
                                                                   0);
                croppedShape.Delete();
                try
                {
                    FileDir.DeleteFile(tempFilePath);
                }
                catch (Exception)
                {
                    // If the file cannot be deleted, we continue without deletion.
                }
            }
            catch (Exception)
            {
                // Revert to normal copy and pasting if unable to create file.
                croppedShape.Cut();
                zoomSlideCroppedShapes = _slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
            }

            zoomSlideCroppedShapes.Name = "PPTLabsMagnifyAreaGroup" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
            Utils.ShapeUtil.FitShapeToSlide(ref zoomSlideCroppedShapes);
            zoomSlideCopy.Delete();
        }
示例#7
0
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();

            var selection = this.GetCurrentSelection();

            PowerPoint.ShapeRange shapeRange;

            try
            {
                shapeRange = selection.ShapeRange;
            }
            catch (Exception)
            {
                MessageBox.Show("Please select an area to magnify.");

                return;
            }

            if (shapeRange.Count > 1 || shapeRange[1].Type == Microsoft.Office.Core.MsoShapeType.msoGroup)
            {
                MessageBox.Show("Only one magnify area is allowed.");

                return;
            }

            try
            {
                var croppedShape = CropToShape.Crop(this.GetCurrentSlide(), selection, isInPlace: true, handleError: false);

                MagnifyGlassEffect(croppedShape, 1.4f);
            }
            catch (Exception e)
            {
                var errorMessage = e.Message;
                errorMessage = errorMessage.Replace("Crop To Shape", "Magnify");

                MessageBox.Show(errorMessage);
            }
        }
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();

            Selection selection = this.GetCurrentSelection();

            ShapeRange shapeRange;

            try
            {
                shapeRange = selection.ShapeRange;
            }
            catch (Exception)
            {
                MessageBox.Show(TextCollection.EffectsLabText.ErrorMagnifyAction);

                return;
            }

            if (shapeRange.Count > 1 || shapeRange[1].Type == Microsoft.Office.Core.MsoShapeType.msoGroup)
            {
                MessageBox.Show(TextCollection.EffectsLabText.ErrorMagnifyOnlyOneArea);

                return;
            }

            try
            {
                Shape croppedShape = CropToShape.Crop(this.GetCurrentSlide(), selection, isInPlace: true, handleError: false);

                MagnifyGlassEffect(croppedShape, 1.4f);
            }
            catch (Exception e)
            {
                string errorMessage = e.Message;
                errorMessage = errorMessage.Replace("Crop To Shape", "Magnify");

                MessageBox.Show(errorMessage);
            }
        }
示例#9
0
        private static string ApplyBlurEffectShape(Models.PowerPointSlide slide, string imageFile, PowerPoint.Shape shape)
        {
            List <string> shapeNames = new List <string>();

            shapeNames.Add(shape.Name);

            if (!string.IsNullOrWhiteSpace(shape.TextFrame2.TextRange.Text))
            {
                shape.ZOrder(Office.MsoZOrderCmd.msoBringToFront);

                PowerPoint.Shape textBox = EffectsLabUtil.DuplicateShapeInPlace(shape);
                textBox.Fill.Visible = Office.MsoTriState.msoFalse;
                textBox.Line.Visible = Office.MsoTriState.msoFalse;
                Utils.ShapeUtil.MoveZToJustInFront(textBox, shape);
                shapeNames.Add(textBox.Name);
            }

            shape.TextFrame2.DeleteText();
            CropToShape.FillInShapeWithImage(slide, imageFile, shape, isInPlace: true);

            if (EffectsLabSettings.IsTintSelected)
            {
                PowerPoint.Shape overlayShape = GenerateOverlayShape(slide, shape);
                shapeNames.Add(overlayShape.Name);
            }

            if (shapeNames.Count > 1)
            {
                PowerPoint.ShapeRange subRange     = slide.Shapes.Range(shapeNames.ToArray());
                PowerPoint.Shape      groupedShape = subRange.Group();

                return(groupedShape.Name);
            }

            return(shapeNames[0]);
        }