Image
کلاس: Image
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import Image ImageRenderOptions: CompositeNode
Image نمایانگر یک تصویر جاسازیشده که در OneNote ذخیره شده است .one فایل. این ویژگی بایتهای خام تصویر، نام فایل اصلی، ابعاد رندر شده، متن alt، URL پیوند (در صورت وجود) و هر برچسب OneNote پیوستشده به تصویر را در اختیار میگذارد.
ImageRenderOptions
| 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) |
ImageRenderOptions
Replace(image)
img.Replace(image: Image) -> Noneمحتوای این را جایگزین میکند Image گره با محتوای گرهای دیگر Image گره، در حافظه. ذخیرهسازی مجدد به .one پشتیبانی نمیشود.
Accept(visitor)
img.Accept(visitor: DocumentVisitor) -> NoneImageRenderOptions 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}")خواندن متن جایگزین (alt text)
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: برچسبها بر روی تصاویر
- ImageRenderOptions: نیاکان Image
- راهنمای توسعهدهنده برای Images و Attached Files
- How-to: پیمایش DOM (KB)