I am using this code to get a crop effect in VSTO addin like crop to fill but setting cropleft or bottom gives exception of value out of range , here is my code try { // Get the active presentation and active window PowerPoint.Presentation activePresentation = Globals.ThisAddIn.Application.ActivePresentation; PowerPoint.DocumentWindow activeWindow = Globals.ThisAddIn.Application.ActiveWindow;
if (activePresentation != null && activeWindow != null)
{
// Get the selection in the active window
PowerPoint.Selection selection = activeWindow.Selection;
if (selection != null)
{
// Check if the selection is a shape
if (selection.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
{
// Get the first selected shape
PowerPoint.Shape selectedShape = selection.ShapeRange[1];
// Check if the selected shape is a picture placeholder
// Set the picture format properties
// Insert the image into the selected shape
selectedShape.Fill.UserPicture(imageUrl);
float currentRotation = selectedShape.Rotation;
float cropLeft = selectedShape.PictureFormat.CropLeft;
float cropRight = selectedShape.PictureFormat.CropRight;
// Adjust the Crop properties for CropToFill effect
selectedShape.PictureFormat.CropLeft = cropLeft;
// selectedShape.LockAspectRatio = MsoTriState.msoTrue;
}
else
{
PowerPoint.Slide activeSlide = (PowerPoint.Slide)Globals.ThisAddIn.Application.ActiveWindow.View.Slide;
// Specify the position and size for the image
float left = 200f; // adjust the values according to your needs
float top = 0;
float width = 400f;
float height = activeSlide.Master.Height;
// Add a picture to the slide
// replace with the actual path to your image file
activeSlide.Shapes.AddPicture(imageUrl, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue,
left, top, width, height);
}
if (downloadUrl != null)
{
unSplash unSplash = new unSplash();
unSplash.MakeDownloadCall(downloadUrl);
}
}
}
}
I am using this code to get a crop effect in VSTO addin like crop to fill but setting cropleft or bottom gives exception of value out of range , here is my code
The
CropLeftproperty returns or sets the number of points that are cropped off the left side of the specified picture or OLE object. Be aware, cropping is calculated relative to the original size of the picture. For example, if you insert a picture that is originally 100 points wide, rescale it so that it is 200 points wide, and then set theCropLeftproperty to 50, 100 points (not 50) will be cropped off the left side of your picture.This following VBA sample code crops the percentage specified by the user off the left of the selected shape, regardless of whether the shape has been scaled. For the example to work, the selected shape must be either a picture or an OLE object.