Interface IImage
Interface that represents a picture in a Excel document.
Namespace: IronXL.Drawing.Images
Assembly: IronXL.dll
Syntax
public interface IImage
IImage is what a worksheet hands back for every picture embedded in a spreadsheet. When code inserts a logo, chart export, or screenshot into a sheet, it works through this contract to reposition that picture, resize it, read its raw bytes, or convert it to a bitmap for further processing. It is the type a developer reaches for when an embedded image needs to be measured, moved, or pulled back out of an .xlsx file rather than just placed once and forgotten. Do not confuse it with ImageFormat, the enumeration that records whether a picture is a PNG or JPEG; IImage is the picture object itself, and exposes that format through its own ImageFormat property.
A developer never constructs an IImage directly. WorkSheet.InsertImage returns one when a picture is added from a file path or a byte array, and the WorkSheet.Images collection (a List<IImage>) holds every image already present in the sheet, so iterating that list is how existing pictures are discovered and edited. Each image belongs to a single worksheet and sits at a cell-anchored location, which is why obtaining the instance from the worksheet, rather than building one in isolation, is the only supported path.
Working with an image centers on a few members. Position reports and adjusts where the picture is anchored on the sheet, Id identifies it for removal through WorkSheet.RemoveImage, and Data exposes the raw bytes for saving the picture elsewhere. Resize() restores the original dimensions, while Resize(double scale) and Resize(double scaleX, double scaleY) scale it uniformly or along each axis. ToAnyBitmap and ToImage convert the embedded picture into an in-memory bitmap when the project needs to inspect or re-encode it. Because the image is tied to its worksheet, saving the workbook persists every change made through these members.
WorkSheet sheet = workbook.DefaultWorkSheet;
IImage image = sheet.InsertImage("logo.png", 1, 1, 3, 4);
image.Resize(0.5, 0.5);The add, extract, and remove worksheet images example saves a picture into a sheet, the worksheet images how-to walks through inserting and reading them back, and the WorkSheet reference documents the InsertImage and Images members that produce them.
Properties
Data
Gets the byte representation of the image.
Declaration
byte[] Data { get; }
Property Value
| Type | Description |
|---|---|
| System.Byte[] |
Id
Gets the index of the image in workbook array.
Declaration
int Id { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
ImageFormat
Gets the format of the image.
Declaration
ImageFormat ImageFormat { get; }
Property Value
| Type | Description |
|---|---|
| ImageFormat |
Position
Gets the position of the image.
Declaration
Position Position { get; }
Property Value
| Type | Description |
|---|---|
| Position |
Methods
Resize()
Reset the image to the dimension of the embedded image
Declaration
void Resize()
Resize(Double)
Resize the image proportionally.
Declaration
void Resize(double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | scale | The scale percentage. |
Resize(Double, Double)
Resize the image.
Please note, that this method works correctly only for workbooks with the default font size (Arial 10pt for .xls and Calibri 11pt for .xlsx). If the default font is changed the resized image can be stretched vertically or horizontally.
Declaration
void Resize(double scaleX, double scaleY)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | scaleX | The scale x (horizontal). 100 is normal scale. |
| System.Double | scaleY | The scale y (vertical). 100 is normal scale. |
ToAnyBitmap()
Creates IronSoftware.Drawing.AnyBitmap object from the image data(array of bytes).
Note : Don't forget to release all the resources used by this Bitmap calling Dispose() method.
Declaration
AnyBitmap ToAnyBitmap()
Returns
| Type | Description |
|---|---|
| IronSoftware.Drawing.AnyBitmap | The newly created IronSoftware.Drawing.AnyBitmap object |
ToImage()
Creates System.Drawing.Image object from the image data(array of bytes).
Note : Don't forget to release all the resources used by this Image calling Dispose() method.
Declaration
Image ToImage()
Returns
| Type | Description |
|---|---|
| SixLabors.ImageSharp.Image | The newly created SixLabors.ImageSharp.Image object |