当前位置: 首页>>代码示例>>C#>>正文


C# MainDocumentPart.AddImagePart方法代码示例

本文整理汇总了C#中DocumentFormat.OpenXml.Packaging.MainDocumentPart.AddImagePart方法的典型用法代码示例。如果您正苦于以下问题:C# MainDocumentPart.AddImagePart方法的具体用法?C# MainDocumentPart.AddImagePart怎么用?C# MainDocumentPart.AddImagePart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentFormat.OpenXml.Packaging.MainDocumentPart的用法示例。


在下文中一共展示了MainDocumentPart.AddImagePart方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddImageParagraph

        private static Paragraph AddImageParagraph(MainDocumentPart mainDocumentPart, List<TextPositon> listTextPositon)
        {
            ImagePart imagePart = mainDocumentPart.AddImagePart(ImagePartType.Jpeg);
            imageRelationshipID = mainDocumentPart.GetIdOfPart(imagePart);
            using (Stream imgStream = imagePart.GetStream())
            {
                System.Drawing.Bitmap logo = new System.Drawing.Bitmap(string.Format(@"{0}\Resources\Wedding_EnclosureCards.jpg", Environment.CurrentDirectory));
                foreach (var item in listTextPositon)
                {
                    System.Drawing.Font font = new System.Drawing.Font("Thaoma", 10, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(logo);
                    float actualWidth = g.MeasureString(item.Text, font).Width;
                    System.Drawing.RectangleF rectf = new System.Drawing.RectangleF((330 - actualWidth) / 2 + item.X, item.Y, 330, 50);

                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                    g.DrawString(item.Text, font, System.Drawing.Brushes.Gray, rectf);

                    g.Flush();
                }
                logo.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            Paragraph p = new Paragraph();
            Run r = new Run();
            Drawing drawing = BuildImage(imageRelationshipID, "sw.gif", 600, 850);
            r.Append(drawing);
            p.Append(r);
            return p;
        }
开发者ID:haizhixing126,项目名称:PYSConsole,代码行数:31,代码来源:WordGenerator.cs

示例2: AddRows

 private void AddRows(MainDocumentPart mainpart, Table t)
 {
     var pr = new PictureRow();
     foreach (var i in q)
     {
         var b = ImageDb.FetchBytes(DbUtil.Db, i.PictureId, 160, 200);
         string iid = "";
         if (b != null)
         {
             ImagePart imagePart = mainpart.AddImagePart(ImagePartType.Jpeg);
             using (var writer = new BinaryWriter(imagePart.GetStream()))
             {
                 writer.Write(b);
             }
             iid = mainpart.GetIdOfPart(imagePart);
         }
         var r = pr.GenerateTableRow(i, iid);
         t.Append(r);
     }
 }
开发者ID:rossspoon,项目名称:bvcms,代码行数:20,代码来源:PictureDir.cs

示例3: FillContent

        private void FillContent(MainDocumentPart mainDocumentPart, IEnumerable<ComplexContentType> controlList)
        {
            foreach (var type in controlList)
            {
                var contentControlByTag = GetContentControlByTag(mainDocumentPart, type.Tag);
                var paragraph = contentControlByTag.Descendants<Paragraph>().FirstOrDefault();

                if (type.ContentType == ContentType.PlainText || type.ContentType == ContentType.RichText)
                {
                    var text = paragraph.Descendants<Text>().FirstOrDefault();
                    if (text != null)
                    {
                        text.Text = contentOfContentControls[type.Tag];

                        var run = text.Parent as Run;
                        if (run != null)
                            run.RunProperties.RunStyle = new RunStyle {Val = "Normal"};
                    }
                }

                if (type.ContentType == ContentType.Picture)
                {
                    var imagePart = mainDocumentPart.AddImagePart(ImagePartType.Gif);
                    using (var fileStream = File.Open("Images\\chess_b_w.gif", FileMode.Open))
                    {
                        imagePart.FeedData(fileStream);
                    }

                    var blipFill = paragraph.Descendants<BlipFill>().FirstOrDefault();
                    var blip = blipFill.GetFirstChild<Blip>();
                    blip.Embed = mainDocumentPart.GetIdOfPart(imagePart);
                    blipFill.SourceRectangle.Remove();
                    contentControlByTag.GetFirstChild<SdtProperties>().GetFirstChild<ShowingPlaceholder>().Remove();
                }
            }
        }
开发者ID:silverforge,项目名称:CKOpenXml,代码行数:36,代码来源:Word.cs

示例4: CreateImagePart

        private string CreateImagePart(MainDocumentPart mainPart, string picturePath)
        {
            ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

            using (FileStream stream = new FileStream(picturePath, FileMode.Open)) {

                imagePart.FeedData(stream);
            }

            return mainPart.GetIdOfPart(imagePart);
        }
开发者ID:FerHenrique,项目名称:Owl,代码行数:11,代码来源:ImageCreator.cs


注:本文中的DocumentFormat.OpenXml.Packaging.MainDocumentPart.AddImagePart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。