Please use the GetShapeRenderer.Save method to save image into a stream or file. ImageSaveOptions allows to specify additional options when rendering document pages or shapes to images. Following code example shows how to save DrawingML and Shape to image file format (Jpeg) and insert it again into Document at same location.
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (DrawingML dml in doc.GetChildNodes(NodeType.DrawingML, true))
{
MemoryStream stream = new MemoryStream();
// Save image to Jpeg
dml.GetShapeRenderer().Save(stream, new ImageSaveOptions(SaveFormat.Jpeg));
builder.MoveTo(dml);
// Insert image again
builder.InsertImage(stream);
dml.Remove();
}
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
MemoryStream stream = new MemoryStream();
// Save image to Jpeg
shape.GetShapeRenderer().Save(stream, new ImageSaveOptions(SaveFormat.Jpeg));
builder.MoveTo(shape);
// Insert image again
builder.InsertImage(stream);
shape.Remove();
}
doc.Save(MyDir + "Out.docx");
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.