Beispiel #1
0
        internal static Picture AddPicture(this Slide slide, Shape referingShape, string imageFile)
        {
            Picture picture = new Picture();

            string      embedId = string.Empty;
            UInt32Value picId   = 10001U;
            string      name    = string.Empty;

            if (slide.Elements <Picture>().Count() > 0)
            {
                picId = ++slide.Elements <Picture>().ToList().Last().NonVisualPictureProperties.NonVisualDrawingProperties.Id;
            }
            name    = "image" + picId.ToString();
            embedId = "rId" + (slide.Elements <Picture>().Count() + 915).ToString(); // some value

            NonVisualPictureProperties nonVisualPictureProperties = new NonVisualPictureProperties()
            {
                NonVisualDrawingProperties = new NonVisualDrawingProperties()
                {
                    Name = name, Id = picId, Title = name
                },
                NonVisualPictureDrawingProperties = new NonVisualPictureDrawingProperties()
                {
                    PictureLocks = new Drawing.PictureLocks()
                    {
                        NoChangeAspect = true
                    }
                },
                ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties()
                {
                    UserDrawn = true
                }
            };

            BlipFill blipFill = new BlipFill()
            {
                Blip = new Drawing.Blip()
                {
                    Embed = embedId
                }
            };

            Drawing.Stretch stretch = new Drawing.Stretch()
            {
                FillRectangle = new Drawing.FillRectangle()
            };
            blipFill.Append(stretch);

            ShapeProperties shapeProperties = new ShapeProperties()
            {
                Transform2D = new Drawing.Transform2D()
                {
                    Offset = new Drawing.Offset()
                    {
                        X = 1554691, Y = 1600200
                    },
                    Extents = new Drawing.Extents()
                    {
                        Cx = 6034617, Cy = 4525963
                    }
                }
            };

            Drawing.PresetGeometry presetGeometry = new Drawing.PresetGeometry()
            {
                Preset = Drawing.ShapeTypeValues.Rectangle
            };
            Drawing.AdjustValueList adjustValueList = new Drawing.AdjustValueList();

            presetGeometry.Append(adjustValueList);
            shapeProperties.Append(presetGeometry);
            picture.Append(nonVisualPictureProperties);
            picture.Append(blipFill);
            picture.Append(shapeProperties);

            slide.CommonSlideData.ShapeTree.Append(picture);

            // Add Image part
            slide.AddImagePart(embedId, imageFile);

            slide.Save();
            return(picture);
        }