Image — Aspose.Note FOSS for Python API Reference

Klase: Image

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

Image pārstāv iegultu attēlu, kas saglabāts OneNote .one failā. Tas atklāj neapstrādātos attēla baitus, oriģinālo faila nosaukumu, attēlotās dimensijas, alternatīvo tekstu, hipersaites URL (ja tāda ir) un jebkurus OneNote tagus, kas pievienoti attēlam.


ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
FileName`strNone`ImageRenderOptions
BytesbytesImageRenderOptionsNeapstrādāti attēla dati (PNG, JPEG vai cits binārais formāts atkarībā no avota)
Width`floatNone`ImageRenderOptions
Height`floatNone`ImageRenderOptions
AlternativeTextTitle`strNone`ImageRenderOptions
AlternativeTextDescription`strNone`ImageRenderOptions
HyperlinkUrl`strNone`ImageRenderOptions
Tagslist[NoteTag]ImageRenderOptionsOneNote birkas, kas pievienotas šim attēlam

Manto no CompositeNode / Node

ImageRenderOptionsImageRenderOptions
ParentNodeIetverošais mezgls (OutlineElement, TableCell)
DocumentSaknes dokuments

ImageRenderOptions

Replace(image)

img.Replace(image: Image) -> None

Aizstāj šī elementa saturu Image mezgls ar cita saturu Image mezgls, atmiņā. Atpakaļ saglabāšana uz .one nav atbalstīts.


Accept(visitor)

img.Accept(visitor: DocumentVisitor) -> None

ImageRenderOptions VisitImageStart(img) un VisitImageEnd(img) apmeklētājam.


Lietošanas piemēri

Saglabāt visus attēlus diskā

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

Noteikt attēla formātu no baitiem

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

Atrast visus saistītos attēlus

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

Nolasīt alternatīvo tekstu

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

Pārbaudīt tagus attēlos

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

Attēli lapā

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 drošība

  • FileName ir None kad nav saglabāts faila nosaukums: vienmēr nodrošiniet rezerves variantu, rakstot uz diska.
  • Bytes vienmēr ir bytes objekts un nekad nav None.
  • Width un Height ir None attēliem, kam nav dimensiju metadatu.
  • AlternativeTextTitle, AlternativeTextDescription, un HyperlinkUrl ir None ja nav iestatīts.

Skatīt arī

 Latviešu