[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.Drawing.IChart.AddPictureInPixel

AddPictureInPixel Method

AddPictureInPixel(string, double, double, double, double)

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.

Declaration
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
Parameters
Type Name Description
string filename

The file from which the picture is created. Must not be null.

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.

Returns
Type Description
IShape

The IShape object that represents the new picture.

Examples
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";
Exceptions
Type Condition
IOException

if the file cannot be read.

AddPictureInPixel(Stream, ImageType, double, double, double, double)

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.

Declaration
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
Parameters
Type Name Description
Stream stream

The stream that provides the image data. Must not be null.

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.

Returns
Type Description
IShape

The IShape object that represents the new picture.

Examples
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";
}