Method AppendImage
AppendImage(Paragraph, byte[], string, Emu, Emu, string?, string?)
Appends an inline picture to a paragraph, adding the image bytes to the document's package and recording the relationship the writer needs.
The bytes are materialized in memory, so the image survives the document being saved more than once and does not depend on any source package staying open.
public static ImageRef AppendImage(this Paragraph paragraph, byte[] imageBytes, string contentType, Emu width, Emu height, string? name = null, string? description = null)
Parameters
paragraphParagraphThe paragraph. It must belong to a document, because the image part and its relationship are document-level state.
imageBytesbyte[]The encoded image bytes. The array is not copied; do not mutate it afterwards.
contentTypestringThe image content type, for example "image/png".
widthEmuThe display width.
heightEmuThe display height.
namestringThe drawing object name, or null to derive one from the part.
descriptionstringThe alternative text, or null.
Returns
- ImageRef
The appended image reference.
Exceptions
- ArgumentNullException
A required argument is null.
- ArgumentException
imageBytesis empty orcontentTypeis not an image type.- InvalidOperationException
The paragraph is not attached to a document.