Travailler avec des images
Extraire les images d’un document OneNote
Toutes les images sont stockées à l’intérieur des nœuds d’image dans un document OneNote.
Extraire des images
Pour extraire toutes les images ou à partir d’un document OneNote, suivez ces étapes:
- Utilisez la méthode Document .getChildNodes pour sélectionner tous les nœuds d’image.
- Ilétèrent à travers les collections de nœuds d’image résultantes.
- Extraire le tableau des octets d’image à l’aide de la propriété Image.Bytes.
- Enregistrer les octets d’image dans un fichier.
L’exemple de code ci-dessous montre comment extraire des images d’un document OneNote et les enregistrer sous forme de fichiers.
Get Information of Each Image from the OneNote Document
The Image class provides all the image properties for images in OneNote documents. All the images of the OneNote file are contained by image nodes in the Document object.
Get Information
The code example given below demonstrates how to get information about each image from a OneNote document.
Insert an Image on a OneNote Document Page
Aspose.Diagram for .NET APIs now allows inserting an image anywhere on the OneNote document.
An image can be inserted in the following ways.
Insert an Image in an Existing OneNote Document
To insert an image on a OneNote document, follow these steps:
- Use the Document.FirstChild property to get the first page.
- Use the Image class constructor to load the image.
- Use the Image.Width and Image.Height properties to adjust the size of the image.
- Use the Image.VerticalOffset and Image.HorizontalOffset properties to set the location of the image.
- Use the Page.AppendChild property to insert the image.
- Save a OneNote document.
The code example given below demonstrates how to insert an image on a OneNote document and save them as files.
Build a OneNote Document from Scratch and Insert an Image
Build a OneNote Document from the Scratch and Insert an Image using an Image Stream
This code example shows how to build a new OneNote document and insert an image using the image stream.
Support for Image Alternative Text
Link an Image to Hyperlink
Remove an Image
1var document = new Document("file.one");
2
3var images = document.GetChildNodes<Image>();
4
5foreach (Aspose.Note.Image image in images)
6{
7 if (image.ParentNode == null)
8 {
9 continue;
10 }
11
12 (image.ParentNode as Page)?.RemoveChild(image);
13 // The parent element of the image can be not only the page
14 (image.ParentNode as OutlineElement)?.RemoveChild(image);
15}
16
17document.Save("after.pdf");