本文整理汇总了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;
}
示例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);
}
}
示例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();
}
}
}
示例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);
}