[]
Creates a picture from an existing file. Returns the IShape object that represents the new picture.
Use this method to insert a picture at the specified position and size, with all coordinates and dimensions measured in pixels.
IShape AddPictureInPixel(string name, string filename, double left, double top, double width, double height)
Function AddPictureInPixel(name As String, filename As String, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The picture name. |
| string | filename | The file from which the object is to be created. |
| double | left | The position (in pixels) of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position (in pixels) of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in pixels. |
| double | height | The height of the picture, in pixels. |
| Type | Description |
|---|---|
| IShape | The IShape object. |
try
{
string imagePath = System.IO.Path.Combine("Users", "DefaultApps", "Documents", "logo.png");
IShape picture = worksheet.Shapes.AddPictureInPixel("CompanyLogo", imagePath, 20, 20, 120, 80);
picture.Name = "CompanyLogo";
}
catch (IOException ex)
{
throw new InvalidOperationException("Unable to add picture in pixel by name from file", ex);
}
| Type | Condition |
|---|---|
| IOException | Thrown if the picture file cannot be read. |
Creates a picture from an existing file and returns the IShape object that represents the new picture.
The picture is positioned and sized by the destination rectangle specified in pixels relative to the upper-left corner of the document.
IShape AddPictureInPixel(string filename, double left, double top, double width, double height)
Function AddPictureInPixel(filename As String, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | filename | The file from which the picture is created. |
| double | left | The position, in pixels, of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position, in pixels, of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in pixels. |
| double | height | The height of the picture, in pixels. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
try
{
string imagePath = System.IO.Path.Combine("Users", "DefaultApps", "Documents", "logo.png");
IShape picture = worksheet.Shapes.AddPictureInPixel(imagePath, 20, 20, 120, 80);
picture.Name = "Logo";
}
catch (IOException ex)
{
throw new InvalidOperationException("Unable to add picture in pixel from file", ex);
}
| Type | Condition |
|---|---|
| IOException | Thrown if the specified file cannot be read. |
Creates a picture from an existing stream. Returns the IShape object that represents the new picture.
The picture is positioned and sized by the destination rectangle specified in pixels relative to the upper-left corner of the document.
IShape AddPictureInPixel(Stream stream, ImageType type, double left, double top, double width, double height)
Function AddPictureInPixel(stream As Stream, type As ImageType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream from which the object is to be created. |
| ImageType | type | Specifies the type of picture to create. |
| double | left | The position (in pixels) of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position (in pixels) of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in pixels. |
| double | height | The height of the picture, in pixels. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
using (MemoryStream stream = CreateSampleImageStream())
{
IShape picture = worksheet.Shapes.AddPictureInPixel(stream, ImageType.PNG, 20, 20, 120, 80);
picture.AlternativeText = "Company logo";
}
| Type | Condition |
|---|---|
| IOException | Thrown if an I/O error occurs while reading the picture stream. |
Creates a picture with the specified name from an existing stream. Returns the IShape object that represents the new picture.
The picture is positioned and sized by the destination rectangle specified in pixels relative to the upper-left corner of the document.
IShape AddPictureInPixel(string name, Stream stream, ImageType type, double left, double top, double width, double height)
Function AddPictureInPixel(name As String, stream As Stream, type As ImageType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The picture name. |
| Stream | stream | The stream from which the picture is created. |
| ImageType | type | Specifies the type of picture to create. |
| double | left | The position (in pixels) of the upper-left corner of the picture relative to the upper-left corner of the document. |
| double | top | The position (in pixels) of the upper-left corner of the picture relative to the top of the document. |
| double | width | The width of the picture, in pixels. |
| double | height | The height of the picture, in pixels. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new picture. |
using (MemoryStream stream = CreateSampleImageStream())
{
IShape picture = worksheet.Shapes.AddPictureInPixel("CompanyLogo", stream, ImageType.PNG, 20, 20, 120, 80);
picture.AlternativeText = "Company logo";
}
| Type | Condition |
|---|---|
| IOException | Thrown if an I/O error occurs while reading the image stream. |