Aspose::Words::Drawing::ImageData::ToByteArray method
Contents
[
Hide
]ImageData::ToByteArray method
Returns image bytes for any image regardless whether the image is stored or linked.
System::ArrayPtr<uint8_t> Aspose::Words::Drawing::ImageData::ToByteArray()
Remarks
If the image is linked, downloads the image every time it is called.
Examples
Shows how to create an image file from a shape’s raw image data.
auto imgSourceDoc = MakeObject<Document>(MyDir + u"Images.docx");
auto imgShape = System::ExplicitCast<Shape>(imgSourceDoc->GetChild(NodeType::Shape, 0, true));
ASSERT_TRUE(imgShape->get_HasImage());
// ToByteArray() returns the array stored in the ImageBytes property.
ASPOSE_ASSERT_EQ(imgShape->get_ImageData()->get_ImageBytes(), imgShape->get_ImageData()->ToByteArray());
// Save the shape's image data to an image file in the local file system.
{
SharedPtr<System::IO::Stream> imgStream = imgShape->get_ImageData()->ToStream();
{
auto outStream = MakeObject<System::IO::FileStream>(ArtifactsDir + u"Drawing.GetDataFromImage.png", System::IO::FileMode::Create,
System::IO::FileAccess::ReadWrite);
imgStream->CopyTo(outStream);
}
}
See Also
- Class ImageData
- Namespace Aspose::Words::Drawing
- Library Aspose.Words for C++