Image
类:Image
Properties: aspose.note Properties: from aspose.note import Image Properties: CompositeNode
Image 表示存储在 OneNote 中的嵌入式图像 .one 文件。它公开原始图像字节、原始文件名、渲染尺寸、替代文本、超链接 URL(如果有),以及附加到图像的任何 OneNote 标签。.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
FileName | `str | None` | Read |
FilePath | `str | None` | Read |
Format | `str | None` | Read |
Bytes | bytes | Read | Gets the bytes. |
OriginalWidth | `float | None` | Read |
OriginalHeight | `float | None` | Read |
Tags | list[NoteTag] | Read | Gets the tags. |
Alignment | `HorizontalAlignment | None` | Read/Write |
Width | `` | Read | Gets the width. |
Height | `` | Read | Gets the height. |
HorizontalOffset | `` | Read | Gets the horizontal offset. |
VerticalOffset | `` | Read | Gets the vertical offset. |
IsBackground | `` | Read | Gets the is background. |
LastModifiedTime | `` | Read | Gets the last modified time. |
AlternativeTextTitle | `` | Read | Gets the alternative text title. |
AlternativeTextDescription | `` | Read | Gets the alternative text description. |
HyperlinkUrl | `` | Read | Gets the hyperlink url. |
FirstChild | `Node | None` | Read |
LastChild | `Node | None` | Read |
ParentNode | `Node | None` | Read |
Document | `Document | None` | Read |
继承自 CompositeNode / Node
| Signature | Description |
|---|---|
| `init(FileName: str | None, 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) |
Properties
Replace(image)
img.Replace(image: Image) -> None替换此 Image 节点的内容为另一个 Image 节点,内存中。保存回 .one 不受支持。.
Accept(visitor)
img.Accept(visitor: DocumentVisitor) -> NoneProperties 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)")从字节检测图像格式
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}")读取替代文本
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当未存储文件名时:写入磁盘时始终提供后备方案。.Bytes始终是一个bytes对象且永不None.Width和Height是None用于没有尺寸元数据的图像。.AlternativeTextTitle,AlternativeTextDescription,,并且HyperlinkUrl是None当未设置时。.
另见
- AttachedFile: 嵌入式文件附件
- NoteTag: 图像标签
- Properties: Image 的祖先
- 图像和附件开发者指南
- How-to: 遍历 DOM(KB)