Image — Aspose.Note FOSS for Python API Reference
Lớp: Image
Enumerations: aspose.note Enumerations: from aspose.note import Image Enumerations: CompositeNode
Image đại diện cho một hình ảnh được nhúng lưu bên trong OneNote .one tệp. Nó cung cấp các byte hình ảnh thô, tên tệp gốc, kích thước hiển thị, văn bản thay thế, URL siêu liên kết (nếu có), và bất kỳ thẻ OneNote nào được gắn vào hình ảnh.
Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
FileName | `str | None` | Enumerations |
Bytes | bytes | Enumerations | Dữ liệu hình ảnh thô (PNG, JPEG, hoặc định dạng nhị phân khác tùy theo nguồn) |
Width | `float | None` | Enumerations |
Height | `float | None` | Enumerations |
AlternativeTextTitle | `str | None` | Enumerations |
AlternativeTextDescription | `str | None` | Enumerations |
HyperlinkUrl | `str | None` | Enumerations |
Tags | list[NoteTag] | Enumerations | Các thẻ OneNote được gắn vào hình ảnh này |
Kế thừa từ CompositeNode / Node
| Enumerations | Enumerations |
|---|---|
ParentNode | Nút chứa (OutlineElement, TableCell) |
Document | Tài liệu gốc |
Enumerations
Replace(image)
img.Replace(image: Image) -> NoneThay thế nội dung của Image nút bằng nội dung của một nút khác Image nút, trong bộ nhớ. Lưu lại vào .one không được hỗ trợ.
Accept(visitor)
img.Accept(visitor: DocumentVisitor) -> NoneEnumerations VisitImageStart(img) và VisitImageEnd(img) trên khách truy cập.
Ví dụ sử dụng
Lưu tất cả hình ảnh vào đĩa
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)")Phát hiện định dạng hình ảnh từ dữ liệu byte
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}")Tìm tất cả các hình ảnh được liên kết
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}")Đọc văn bản thay thế (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}")Kiểm tra các thẻ trên hình ảnh
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}")Hình ảnh trên mỗi trang
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-Safety
FileNamelàNonekhi không có tên tệp được lưu: luôn cung cấp một phương án dự phòng khi ghi vào đĩa.Bytesluôn là mộtbytesđối tượng và không bao giờNone.WidthvàHeightlàNonecho các hình ảnh không có siêu dữ liệu kích thước.AlternativeTextTitle,AlternativeTextDescription, vàHyperlinkUrllàNonekhi chưa được đặt.
Xem Thêm
- AttachedFile: tệp đính kèm nhúng
- NoteTag: thẻ trên hình ảnh
- Enumerations: tổ tiên của Image
- Hướng dẫn nhà phát triển cho Images và Attached Files
- Cách thực hiện: Duyệt DOM (KB)