이미지 작업

Aspose.Words 사용자가 매우 유연한 방법으로 이미지를 작업 할 수 있습니다. 이 기사에서는 이미지 작업의 가능성 중 일부만 탐색 할 수 있습니다.

문서에서 이미지를 추출하는 방법

모든 이미지는 내부에 저장됩니다 Shape 노드 Document. 문서에서 특정 형식을 가진 모든 이미지 또는 이미지를 추출하려면 다음과 같이 하십시오:

  • 사용 GetChildNodes 모두 선택하는 방법 Shape 노드
  • 결과 노드 컬렉션을 반복합니다.
  • 확인 HasImage 부울 속성.
  • 다음을 사용하여 이미지 데이터 추출 ImageData 재산.
  • 이미지 데이터를 파일에 저장합니다.

다음 코드 예제에서는 문서에서 이미지를 추출하여 파일로 저장하는 방법을 보여 줍니다:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directories.
System::String inputDataDir = GetInputDataDir_WorkingWithImages();
System::String outputDataDir = GetOutputDataDir_WorkingWithImages();
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Image.SampleImages.doc");
System::SharedPtr<NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
int32_t imageIndex = 0;
for (System::SharedPtr<Shape> shape : System::IterateOver<System::SharedPtr<Shape>>(shapes))
{
if (shape->get_HasImage())
{
System::String imageFileName = System::String::Format(u"Image.ExportImages.{0}.{1}", imageIndex, FileFormatUtil::ImageTypeToExtension(shape->get_ImageData()->get_ImageType()));
System::String imagePath = outputDataDir + imageFileName;
shape->get_ImageData()->Save(imagePath);
std::cout << "Image saved at " << imagePath.ToUtf8String() << std::endl;
imageIndex++;
}
}

다른 이름으로 이미지 저장 WMF

Aspose.Words 문서에서 사용 가능한 모든 이미지를 저장하는 기능을 제공합니다. WMF 변환하는 동안 포맷 DOCX 에 RTF.

다음 코드 예제에서는 이미지를 다른 이름으로 저장하는 방법을 보여 줍니다 WMF 함께 RTF 저장 옵션:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"TestFile.doc");
System::SharedPtr<RtfSaveOptions> options = System::MakeObject<RtfSaveOptions>();
options->set_SaveImagesAsWmf(true);
doc->Save(outputDataDir + u"WorkingWithRtfSaveOptions.SavingImagesAsWmf.rtf", options);