Image — Aspose.Note FOSS for Python API Reference

Клас: Image

Enumerations: aspose.note Enumerations: from aspose.note import Image Enumerations: CompositeNode

Image представляє вбудоване зображення, збережене всередині OneNote .one файл. Воно надає необроблені байти зображення, оригінальне ім’я файлу, відображені розміри, альтернативний текст, URL‑посилання (за наявності) та будь‑які теги OneNote, прикріплені до зображення.


Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
FileName`strNone`Enumerations
BytesbytesEnumerationsНеоброблені дані зображення (PNG, JPEG або інший бінарний формат залежно від джерела)
Width`floatNone`Enumerations
Height`floatNone`Enumerations
AlternativeTextTitle`strNone`Enumerations
AlternativeTextDescription`strNone`Enumerations
HyperlinkUrl`strNone`Enumerations
Tagslist[NoteTag]EnumerationsТеги OneNote, прикріплені до цього зображення

Успадковано від CompositeNode / Node

EnumerationsEnumerations
ParentNodeВузол, що містить (OutlineElement, TableCell)
DocumentКореневий документ

Enumerations

Replace(image)

img.Replace(image: Image) -> None

Замінює вміст цього Image вузла вмістом іншого Image вузла, в пам’яті. Збереження назад у .one не підтримується.


Accept(visitor)

img.Accept(visitor: DocumentVisitor) -> None

Enumerations VisitImageStart(img) і VisitImageEnd(img) на відвідувача.


Приклади використання

Зберегти всі зображення на диск

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for i, img in enumerate(doc.GetChildNodes(Image), start=1):
    filename = img.FileName or f"image_{i}.bin"
    with open(filename, "wb") as f:
        f.write(img.Bytes)
    print(f"Saved: {filename}  ({img.Width} x {img.Height} pts)")

Визначити формат зображення за байтами

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    b = img.Bytes
    if b[:4] == b'\x89PNG':
        fmt = "png"
    elif b[:2] == b'\xff\xd8':
        fmt = "jpeg"
    elif b[:4] == b'GIF8':
        fmt = "gif"
    else:
        fmt = "bin"
    print(f"  {img.FileName!r} detected as {fmt}")

Знайти всі пов’язані зображення

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    if img.HyperlinkUrl:
        print(f"  Linked image: {img.FileName!r} -> {img.HyperlinkUrl}")

Прочитати альтернативний текст

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    if img.AlternativeTextTitle or img.AlternativeTextDescription:
        print(f"  Alt title: {img.AlternativeTextTitle!r}")
        print(f"  Alt desc:  {img.AlternativeTextDescription!r}")

Перевірити теги на зображеннях

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    for tag in img.Tags:
        print(f"  Image tag: label={tag.label!r}  completed={tag.completed}")

Зображень на сторінці

from aspose.note import Document, Page, Image

doc = Document("MyNotes.one")
for page_num, page in enumerate(doc.GetChildNodes(Page), start=1):
    images = page.GetChildNodes(Image)
    print(f"Page {page_num}: {len(images)} image(s)")

Безпека щодо None

  • FileName є None коли не збережено ім’я файлу: завжди забезпечуйте резервний варіант під час запису на диск.
  • Bytes завжди є bytes об’єктом і ніколи не None.
  • Width і Height є None для зображень без метаданих розмірів.
  • AlternativeTextTitle, AlternativeTextDescription, і HyperlinkUrl є None коли не встановлено.

Див. також

 Українська