-
Notifications
You must be signed in to change notification settings - Fork 0
Images
Namespace: ParentElement.RichText.Core.Images
Support for inline images that flow with document text, cursor shape hints, and image resize handle identification.
An image that flows with text as a U+FFFC Object Replacement Character placeholder. Implements IInlineObject so the RichTextKit layout engine can measure and paint it correctly.
public class InlineImage : IInlineObjectpublic InlineImage(SKImage image, float displayWidth, float displayHeight)| Parameter | Type | Description |
|---|---|---|
image |
SKImage |
The SkiaSharp image to render |
displayWidth |
float |
Display width in pixels |
displayHeight |
float |
Display height in pixels |
| Property | Type | Description |
|---|---|---|
Width |
float |
Display width in pixels (mutable for resize operations) |
Height |
float |
Display height in pixels (mutable for resize operations) |
Image |
SKImage |
The underlying Skia image |
| Method | Returns | Description |
|---|---|---|
Paint(SKCanvas, SKPoint origin) |
void |
Render the image at the given origin using bilinear filtering |
GetPngBytes() |
byte[] |
Return PNG-encoded bytes for export (clipboard, RTF, etc.) |
Images are inserted via IDocumentController.InsertInlineImage and are embedded in the document as InlineImage instances:
// Insert from a file
using var stream = File.OpenRead("photo.png");
var skImage = SKImage.FromEncodedData(stream);
editor.InsertInlineImage(skImage, displayWidth: 400, displayHeight: 300);
// Insert from bytes (e.g. from clipboard)
var bytes = await clipboard.GetImageDataAsync();
if (bytes != null)
{
var skImage = SKImage.FromEncodedData(bytes);
editor.InsertInlineImage(skImage, skImage.Width, skImage.Height);
}When reading document content, image runs expose ContentRun.ImageData (PNG bytes) rather than the live InlineImage object:
foreach (var run in block.Runs)
{
if (run.IsImage)
{
// run.ImageData → PNG bytes
// run.ImageWidth → display width
// run.ImageHeight → display height
}
}Platform-agnostic cursor hint sent to the UI layer via IDocumentController.RequestCursorUpdate. Map each value to your platform's native cursor.
public enum EditorCursor| Value | Description |
|---|---|
Default |
Standard text / arrow cursor |
ResizeNS |
North–south resize (top or bottom edge handle) |
ResizeEW |
East–west resize (left or right edge handle) |
ResizeDiagNWSE |
Diagonal NW↔SE resize (TopLeft / BottomRight corner handles) |
ResizeDiagNESW |
Diagonal NE↔SW resize (TopRight / BottomLeft corner handles) |
Move |
Four-directional move cursor (over the image body) |
editor.RequestCursorUpdate = cursor =>
{
Cursor = cursor switch
{
EditorCursor.ResizeNS => new Cursor(StandardCursorType.SizeNorthSouth),
EditorCursor.ResizeEW => new Cursor(StandardCursorType.SizeWestEast),
EditorCursor.ResizeDiagNWSE => new Cursor(StandardCursorType.SizeNorthWestSouthEast),
EditorCursor.ResizeDiagNESW => new Cursor(StandardCursorType.SizeNorthEastSouthWest),
EditorCursor.Move => new Cursor(StandardCursorType.SizeAll),
_ => new Cursor(StandardCursorType.Ibeam),
};
};Identifies which resize handle is being dragged on a selected inline image.
public enum ResizeHandleType| Value | Position | Behaviour |
|---|---|---|
None |
— | No handle (not over a handle) |
TopLeft |
Corner | Maintains aspect ratio |
TopCenter |
Edge | Resizes height only |
TopRight |
Corner | Maintains aspect ratio |
MiddleRight |
Edge | Resizes width only |
BottomRight |
Corner | Maintains aspect ratio |
BottomCenter |
Edge | Resizes height only |
BottomLeft |
Corner | Maintains aspect ratio |
MiddleLeft |
Edge | Resizes width only |
Corner handles (TopLeft, TopRight, BottomRight, BottomLeft) constrain the resize to maintain the image's original aspect ratio. Edge handles (TopCenter, MiddleRight, BottomCenter, MiddleLeft) resize a single axis freely.
See also: IDocumentController · Content-Model