[]
Creates a picture from an existing file and adds it to the chart using pixel-based coordinates.
The picture is positioned relative to the upper-left corner of the chart area, and the returned IShape represents the newly created picture.
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. Must not be |
| double | left | The distance from the left edge of the picture to the left edge of the chart area, in pixels. |
| double | top | The distance from the top edge of the picture to the top edge of the chart area, in pixels. |
| 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. |
IChart chart = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 20, 20, 300, 200).Chart;
string imagePath = System.IO.Path.Combine("Users", "DefaultApps", "Documents", "logo.png");
IShape picture = chart.AddPictureInPixel(imagePath, 30, 25, 80, 60);
picture.Name = "Logo";
| Type | Condition |
|---|---|
| IOException | if the file cannot be read. |
Creates a picture from an existing stream at the specified position and size, measured in pixels.
The picture is added relative to the chart area. Use this method when the image content is available as a stream and the picture position and size need to be specified in pixel units.
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 that provides the image data. Must not be |
| ImageType | type | The image type of the stream data. |
| double | left | The distance from the left edge of the picture to the left edge of the chart area, in pixels. |
| double | top | The distance from the top edge of the picture to the top edge of the chart area, in pixels. |
| 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. |
IChart chart = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 20, 20, 300, 200).Chart;
byte[] pictureBytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jmioAAAAASUVORK5CYII=");
IShape picture;
using (MemoryStream stream = new MemoryStream(pictureBytes))
{
picture = chart.AddPictureInPixel(stream, ImageType.PNG, 30, 25, 80, 60);
picture.Name = "Logo";
}