我使用此代码在 VSTO 插件中获得裁剪效果,例如裁剪填充,但设置cropleft或bottom会给出值超出范围的异常,这是我的代码 尝试 { // 获取活动演示文稿和活动窗口 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);
}
}
}
}
我使用此代码在 VSTO 插件中获得裁剪效果,例如裁剪填充,但设置cropleft或bottom会给出值超出范围的异常,这是我的代码
CropLeft
属性返回或设置从指定图片或 OLE 对象左侧裁剪的点数。请注意,裁剪是相对于图片的原始大小计算的。例如,如果您插入一张原本宽度为 100 磅的图片,将其重新缩放为 200 磅宽,然后将 CropLeft
属性设置为 50,则 100 磅(而不是 50)将被裁剪掉左侧你的照片。
以下 VBA 示例代码将从所选形状的左侧裁剪用户指定的百分比,无论形状是否已缩放。为了使示例正常工作,所选形状必须是图片或 OLE 对象。
percentToCrop = InputBox("What percentage do you " & _
"want to crop off the bottom of this picture?")
Set shapeToCrop = ActiveWindow.Selection.ShapeRange(1)
With shapeToCrop.Duplicate
.ScaleHeight 1, True
origHeight = .Height
.Delete
End With
cropPoints = origHeight * percentToCrop / 100
shapeToCrop.PictureFormat.CropLeft = cropPoints