Image

Κλάση: Image

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

Image αντιπροσωπεύει μια ενσωματωμένη εικόνα που αποθηκεύεται μέσα σε ένα OneNote .one αρχείο. Εκθέτει τα ακατέργαστα bytes της εικόνας, το αρχικό όνομα αρχείου, τις αποδοθείσες διαστάσεις, το κείμενο alt, μια διεύθυνση URL υπερσύνδεσης (εάν υπάρχει) και τυχόν ετικέτες OneNote που είναι συνδεδεμένες με την εικόνα.


ImageRenderOptions

NameTypeAccessDescription
FileName`strNone`Read
FilePath`strNone`Read
Format`strNone`Read
BytesbytesReadGets the bytes.
OriginalWidth`floatNone`Read
OriginalHeight`floatNone`Read
Tagslist[NoteTag]ReadGets the tags.
Alignment`HorizontalAlignmentNone`Read/Write
Width``ReadGets the width.
Height``ReadGets the height.
HorizontalOffset``ReadGets the horizontal offset.
VerticalOffset``ReadGets the vertical offset.
IsBackground``ReadGets the is background.
LastModifiedTime``ReadGets the last modified time.
AlternativeTextTitle``ReadGets the alternative text title.
AlternativeTextDescription``ReadGets the alternative text description.
HyperlinkUrl``ReadGets the hyperlink url.
FirstChild`NodeNone`Read
LastChild`NodeNone`Read
ParentNode`NodeNone`Read
Document`DocumentNone`Read

Κληρονομείται από CompositeNode / Node

SignatureDescription
`init(FileName: strNone, FilePath: str
Replace(image: Image)Replaces the current image data with the provided Image instance
AppendChildLast(node: TNode)TNode
AppendChildFirst(node: TNode)TNode
InsertChild(index: int, node: TNode)TNode
RemoveChild(node: Node)
GetEnumerator()Iterator[Node]
GetChildNodes(node_type: type[TNode])list[TNode]
Accept(visitor: DocumentVisitor)

ImageRenderOptions

Replace(image)

img.Replace(image: Image) -> None

Αντικαθιστά το περιεχόμενο αυτού του Image node με το περιεχόμενο ενός άλλου Image node, στη μνήμη. Αποθήκευση πίσω σε .one δεν υποστηρίζεται.


Accept(visitor)

img.Accept(visitor: DocumentVisitor) -> None

ImageRenderOptions 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)")

Ανίχνευση μορφής εικόνας από τα bytes

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}")


### Εύρεση όλων των συνδεδεμένων εικόνων

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

Ανάγνωση κειμένου alt

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}")


### Επιθεώρηση ετικετών στις εικόνες

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 όταν δεν αποθηκεύτηκε όνομα αρχείου: πάντα παρέχετε εναλλακτική λύση όταν γράφετε στο disk.
  • Bytes είναι πάντα ένα bytes αντικείμενο και δεν είναι ποτέ None.
  • Width και Height είναι None για εικόνες χωρίς μεταδεδομένα διαστάσεων.
  • AlternativeTextTitle, AlternativeTextDescription, και HyperlinkUrl είναι None όταν δεν έχει οριστεί.

Δείτε επίσης

 Ελληνικά