Image — Aspose.Note FOSS for Python API Reference
Class: Image
Properties: aspose.note Properties: from aspose.note import Image Properties: CompositeNode
Image เป็นภาพฝังที่จัดเก็บอยู่ใน OneNote .one ไฟล์ มันเปิดเผยไบต์ของภาพดิบ, ชื่อไฟล์ต้นฉบับ, มิติที่แสดงผล, alt text, hyperlink URL (ถ้ามี) และแท็ก OneNote ใด ๆ ที่แนบกับภาพ.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
FileName | `str | None` | Properties |
Bytes | bytes | Properties | ข้อมูลภาพดิบ (PNG, JPEG หรือรูปแบบไบนารีอื่น ๆ ขึ้นอยู่กับแหล่งที่มา) |
Width | `float | None` | Properties |
Height | `float | None` | Properties |
AlternativeTextTitle | `str | None` | Properties |
AlternativeTextDescription | `str | None` | Properties |
HyperlinkUrl | `str | None` | Properties |
Tags | list[NoteTag] | Properties | แท็ก OneNote ที่แนบมาพร้อมกับภาพนี้ |
สืบทอดจาก CompositeNode / Node
| Properties | Properties |
|---|---|
ParentNode | โหนดที่บรรจุ (OutlineElement, TableCell) |
Document | เอกสารราก |
Properties
Replace(image)
img.Replace(image: Image) -> Noneแทนที่เนื้อหาของนี้ Image โหนดด้วยเนื้อหาของโหนดอื่น Image โหนดในหน่วยความจำ การบันทึกกลับไปยัง .one ไม่รองรับ.
Accept(visitor)
img.Accept(visitor: DocumentVisitor) -> NoneProperties VisitImageStart(img) และ VisitImageEnd(img) บนผู้เยี่ยมชม.
ตัวอย่างการใช้งาน
Save all images to 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)")Detect image format from bytes
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}")Find all linked images
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}")Read alt text
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}")Inspect tags on images
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}")Images per page
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เมื่อไม่ได้ตั้งค่า.
ดูเพิ่มเติม
- AttachedFile: ไฟล์แนบที่ฝังอยู่
- NoteTag: แท็กบนภาพ
- Properties: บรรพบุรุษของ Image
- Images and Attached Files Developer Guide
- How-to: Traverse the DOM (KB)