to_byte_array method

to_byte_array()

Returns image bytes for any image regardless whether the image is stored or linked.

def to_byte_array(self):
    ...

Remarks

If the image is linked, downloads the image every time it is called.

Returns

Examples

Shows how to create an image file from a shape’s raw image data.

img_source_doc = aw.Document(MY_DIR + 'Images.docx')
img_shape = img_source_doc.get_child(aw.NodeType.SHAPE, 0, True).as_shape()
self.assertTrue(img_shape.has_image)
# to_byte_array() returns the array stored in the "image_bytes" property.
self.assertEqual(img_shape.image_data.image_bytes, img_shape.image_data.to_byte_array())
# Save the shape's image data to an image file in the local file system.
with img_shape.image_data.to_stream() as img_stream:
    with open(ARTIFACTS_DIR + 'Drawing.get_data_from_image.png', 'wb') as out_stream:
        out_stream.write(img_stream.read())

See Also