OpenXML - PowerPoint - 图片比例高度和宽度

OpenXML - PowerPoint - Picture Scale Height & Width

我正在尝试使用 PowerPoint 演示文稿 PPTX 文件中图片的 OpenXML SDK 查找或计算比例高度和宽度值。

我得到的图像是

Picture = DocumentFormat.OpenXml.Presentation.Picture

我查看了 ShapeProperties 和 NonVisualPictureProperties,但无法找到这些值。

这就是我在查看 PowerPoint 内部时试图以编程方式获取的内容

谁能告诉我这些值隐藏在哪里?

谢谢

检查 DocumentFormat.OpenXml.Drawing -> ShapeProperties.Transform2D.Extents。 (Extent documentation)。这是绝妙的 OpenXML EMU 中的绝对大小,而不是百分比(1 英寸 = 914400 个 EMU,1 厘米 = 360000 个 EMU)。据我所知,这是您设置图像比例的方式(绝对值,而不是百分比)。

使用OpenXML SDK工具反映示例代码:新建电子表格,插入图片,保存。然后在 openxml sdk->reflect 代码中,ctrl+f "Transform2D" 应该可以得到你需要的东西。例如:

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml;
using A = DocumentFormat.OpenXml.Drawing;
using P14 = DocumentFormat.OpenXml.Office2010.PowerPoint;
using P15 = DocumentFormat.OpenXml.Office2013.PowerPoint;
using A14 = DocumentFormat.OpenXml.Office2010.Drawing;
using Thm15 = DocumentFormat.OpenXml.Office2013.Theme;
using Ap = DocumentFormat.OpenXml.ExtendedProperties;
using Vt = DocumentFormat.OpenXml.VariantTypes;

// Generates content of slidePart1.
private void GenerateSlidePart1Content(SlidePart slidePart1)
{
    Slide slide1 = new Slide();
    slide1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
    slide1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    slide1.AddNamespaceDeclaration("p", "http://schemas.openxmlformats.org/presentationml/2006/main");

    CommonSlideData commonSlideData1 = new CommonSlideData();

    ShapeTree shapeTree1 = new ShapeTree();

    NonVisualGroupShapeProperties nonVisualGroupShapeProperties1 = new NonVisualGroupShapeProperties();
    NonVisualDrawingProperties nonVisualDrawingProperties1 = new NonVisualDrawingProperties(){ Id = (UInt32Value)1U, Name = "" };
    NonVisualGroupShapeDrawingProperties nonVisualGroupShapeDrawingProperties1 = new NonVisualGroupShapeDrawingProperties();
    ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();

    nonVisualGroupShapeProperties1.Append(nonVisualDrawingProperties1);
    nonVisualGroupShapeProperties1.Append(nonVisualGroupShapeDrawingProperties1);
    nonVisualGroupShapeProperties1.Append(applicationNonVisualDrawingProperties1);

    GroupShapeProperties groupShapeProperties1 = new GroupShapeProperties();

    A.TransformGroup transformGroup1 = new A.TransformGroup();
    A.Offset offset1 = new A.Offset(){ X = 0L, Y = 0L };
    A.Extents extents1 = new A.Extents(){ Cx = 0L, Cy = 0L };
    A.ChildOffset childOffset1 = new A.ChildOffset(){ X = 0L, Y = 0L };
    A.ChildExtents childExtents1 = new A.ChildExtents(){ Cx = 0L, Cy = 0L };

    transformGroup1.Append(offset1);
    transformGroup1.Append(extents1);
    transformGroup1.Append(childOffset1);
    transformGroup1.Append(childExtents1);

    groupShapeProperties1.Append(transformGroup1);

    Picture picture1 = new Picture();

    NonVisualPictureProperties nonVisualPictureProperties1 = new NonVisualPictureProperties();
    NonVisualDrawingProperties nonVisualDrawingProperties2 = new NonVisualDrawingProperties(){ Id = (UInt32Value)4U, Name = "Picture 3" };

    NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 = new NonVisualPictureDrawingProperties();
    A.PictureLocks pictureLocks1 = new A.PictureLocks(){ NoChangeAspect = true };

    nonVisualPictureDrawingProperties1.Append(pictureLocks1);
    ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties2 = new ApplicationNonVisualDrawingProperties();

    nonVisualPictureProperties1.Append(nonVisualDrawingProperties2);
    nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);
    nonVisualPictureProperties1.Append(applicationNonVisualDrawingProperties2);

    BlipFill blipFill1 = new BlipFill();

    A.Blip blip1 = new A.Blip(){ Embed = "rId2" };

    A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();

    A.BlipExtension blipExtension1 = new A.BlipExtension(){ Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };

    A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi(){ Val = false };
    useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");

    blipExtension1.Append(useLocalDpi1);

    blipExtensionList1.Append(blipExtension1);

    blip1.Append(blipExtensionList1);

    A.Stretch stretch1 = new A.Stretch();
    A.FillRectangle fillRectangle1 = new A.FillRectangle();

    stretch1.Append(fillRectangle1);

    blipFill1.Append(blip1);
    blipFill1.Append(stretch1);

    ShapeProperties shapeProperties1 = new ShapeProperties();

    A.Transform2D transform2D1 = new A.Transform2D();
    A.Offset offset2 = new A.Offset(){ X = 1524000L, Y = 0L };
    A.Extents extents2 = new A.Extents(){ Cx = 9144000L, Cy = 6858000L };

    transform2D1.Append(offset2);
    transform2D1.Append(extents2);

    A.PresetGeometry presetGeometry1 = new A.PresetGeometry(){ Preset = A.ShapeTypeValues.Rectangle };
    A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

    presetGeometry1.Append(adjustValueList1);

    shapeProperties1.Append(transform2D1);
    shapeProperties1.Append(presetGeometry1);

    picture1.Append(nonVisualPictureProperties1);
    picture1.Append(blipFill1);
    picture1.Append(shapeProperties1);

    shapeTree1.Append(nonVisualGroupShapeProperties1);
    shapeTree1.Append(groupShapeProperties1);
    shapeTree1.Append(picture1);

    CommonSlideDataExtensionList commonSlideDataExtensionList1 = new CommonSlideDataExtensionList();

    CommonSlideDataExtension commonSlideDataExtension1 = new CommonSlideDataExtension(){ Uri = "{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}" };

    P14.CreationId creationId1 = new P14.CreationId(){ Val = (UInt32Value)568547621U };
    creationId1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main");

    commonSlideDataExtension1.Append(creationId1);

    commonSlideDataExtensionList1.Append(commonSlideDataExtension1);

    commonSlideData1.Append(shapeTree1);
    commonSlideData1.Append(commonSlideDataExtensionList1);

    ColorMapOverride colorMapOverride1 = new ColorMapOverride();
    A.MasterColorMapping masterColorMapping1 = new A.MasterColorMapping();

    colorMapOverride1.Append(masterColorMapping1);

    slide1.Append(commonSlideData1);
    slide1.Append(colorMapOverride1);

    slidePart1.Slide = slide1;
}