Class Picture

Class Picture

Namespace: Aspose.Cells.Drawing
Assembly: Aspose.Cells.dll (25.2.0)

Encapsulates the object that represents a single picture in a spreadsheet.

public class Picture : Shape

Inheritance

objectShapePicture

Inherited Members

Shape.GetResultOfSmartArt(), Shape.ToFrontOrBack(int), Shape.GetLockedProperty(ShapeLockType), Shape.SetLockedProperty(ShapeLockType, bool), Shape.AddHyperlink(string), Shape.RemoveHyperlink(), Shape.MoveToRange(int, int, int, int), Shape.AlignTopRightCorner(int, int), Shape.GetConnectionPoints(), Shape.ToImage(Stream, ImageType), Shape.ToImage(string, ImageOrPrintOptions), Shape.ToImage(Stream, ImageOrPrintOptions), Shape.GetLinkedCell(bool, bool), Shape.SetLinkedCell(string, bool, bool), Shape.GetInputRange(bool, bool), Shape.SetInputRange(string, bool, bool), Shape.UpdateSelectedValue(), Shape.CalculateTextSize(), Shape.FormatCharacters(int, int, Font, StyleFlag), Shape.Characters(int, int), Shape.GetRichFormattings(), Shape.RemoveActiveXControl(), Shape.IsSameSetting(object), Shape.GetActualBox(), Shape.MacroName, Shape.IsEquation, Shape.IsSmartArt, Shape.ZOrderPosition, Shape.Name, Shape.AlternativeText, Shape.Title, Shape.Line, Shape.Fill, Shape.ShadowEffect, Shape.Reflection, Shape.Glow, Shape.SoftEdges, Shape.ThreeDFormat, Shape.FormatPicture, Shape.IsHidden, Shape.IsAspectRatioLocked, Shape.RotationAngle, Shape.Hyperlink, Shape.Id, Shape.Spid, Shape.Spt, Shape.Worksheet, Shape.IsGroup, Shape.IsInGroup, Shape.IsWordArt, Shape.TextEffect, Shape.IsLocked, Shape.IsPrintable, Shape.MsoDrawingType, Shape.AutoShapeType, Shape.AnchorType, Shape.Placement, Shape.UpperLeftRow, Shape.UpperDeltaY, Shape.UpperLeftColumn, Shape.UpperDeltaX, Shape.LowerRightRow, Shape.LowerDeltaY, Shape.LowerRightColumn, Shape.LowerDeltaX, Shape.Right, Shape.Bottom, Shape.Width, Shape.WidthInch, Shape.WidthPt, Shape.WidthCM, Shape.Height, Shape.HeightInch, Shape.HeightPt, Shape.HeightCM, Shape.Left, Shape.LeftInch, Shape.LeftCM, Shape.Top, Shape.TopInch, Shape.TopCM, Shape.TopToCorner, Shape.LeftToCorner, Shape.X, Shape.Y, Shape.WidthScale, Shape.HeightScale, Shape.TopInShape, Shape.LeftInShape, Shape.WidthInShape, Shape.HeightInShape, Shape.Group, Shape.Type, Shape.HasLine, Shape.IsFilled, Shape.IsFlippedHorizontally, Shape.IsFlippedVertically, Shape.ActualLowerRightRow, Shape.RelativeToOriginalPictureSize, Shape.LinkedCell, Shape.InputRange, Shape.TextShapeType, Shape.TextBody, Shape.Font, Shape.TextOptions, Shape.Text, Shape.IsRichText, Shape.HtmlText, Shape.TextVerticalOverflow, Shape.TextHorizontalOverflow, Shape.IsTextWrapped, Shape.TextOrientationType, Shape.TextHorizontalAlignment, Shape.TextVerticalAlignment, Shape.TextDirection, Shape.TextBoxOptions, Shape.ControlData, Shape.ActiveXControl, Shape.Paths, Shape.Geometry, Shape.CreateId, Shape.IsDecorative, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a picture at the location of a cell whose row and column indices
//are 5 in the worksheet. It is "F6" cell
worksheet.Pictures.Add(5, 5, "image.gif");
//Saving the Excel file
workbook.Save("book1.xls", SaveFormat.Excel97To2003);
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Workbook object
Dim sheetIndex As Integer = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a picture at the location of a cell whose row and column indices
'are 5 in the worksheet. It is "F6" cell
worksheet.Pictures.Add(5, 5, "image.gif")
'Saving the Excel file
workbook.Save("book1.xls", SaveFormat.Excel97To2003)

Properties

BorderLineColor

Represents the System.Drawing.Color of the border line of a picture.

public Color BorderLineColor { get; set; }

Property Value

Color

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Set the border color of the picture
pic.BorderLineColor = Color.Red;
//Save the excel file.
workbook.Save("result.xlsx");

BorderWeight

Gets or sets the weight of the border line of a picture in units of pt.

public double BorderWeight { get; set; }

Property Value

double

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Set the border color of the picture
pic.BorderLineColor = Color.Red;
//Set the border width of the picture
pic.BorderWeight = 3;
//Save the excel file.
workbook.Save("result.xlsx");

Data

Gets the data of the picture.

public byte[] Data { get; set; }

Property Value

byte[]

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "example1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "example2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
//Assign the byte data of the first image to the second image
pic2.Data = pic1.Data;
//Save the excel file.
workbook.Save("result.xlsx");

DisplayAsIcon

True if the specified object is displayed as an icon and the image will not be auto changed.

public bool DisplayAsIcon { get; set; }

Property Value

bool

Formula

Gets and sets the data of the formula.

public string Formula { get; set; }

Property Value

string

ImageType

Gets the image format of the picture.

public ImageType ImageType { get; }

Property Value

ImageType

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
if(pic1.ImageType == Aspose.Cells.Drawing.ImageType.Png)
{
    //The picture's type is png.";
}
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
if(pic2.ImageType == Aspose.Cells.Drawing.ImageType.Jpeg)
{
    //The picture's type is jpg.";
}

IsAutoSize

True indicates that the size of the ole object will be auto changed as the size of snapshot of the embedded content when the ole object is activated.

public bool IsAutoSize { get; set; }

Property Value

bool

IsDynamicDataExchange

Gets or sets whether dynamic data exchange

public bool IsDynamicDataExchange { get; set; }

Property Value

bool

IsLink

Returns true if the picture is linked to a file.

public bool IsLink { get; set; }

Property Value

bool

OriginalHeight

Gets the original height of the picture.

public int OriginalHeight { get; }

Property Value

int

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original height of the picture.
int picHeight = pic.OriginalHeight;
//Save the excel file.
workbook.Save("result.xlsx");

OriginalHeightCM

Gets the original height of picture, in unit of centimeters.

public double OriginalHeightCM { get; }

Property Value

double

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original height of the picture.
double picHeightCM = pic.OriginalHeightCM;
//Save the excel file.
workbook.Save("result.xlsx");

OriginalHeightInch

Gets the original height of picture, in unit of inches.

public double OriginalHeightInch { get; }

Property Value

double

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original height of the picture.
double picHeightInch = pic.OriginalHeightInch;
//Save the excel file.
workbook.Save("result.xlsx");

OriginalWidth

Gets the original width of the picture.

public int OriginalWidth { get; }

Property Value

int

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original width of the picture.
int picWidth = pic.OriginalWidth;
//Save the excel file.
workbook.Save("result.xlsx");

OriginalWidthCM

Gets the original width of picture, in unit of centimeters.

public double OriginalWidthCM { get; }

Property Value

double

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original width of the picture.
double picWidthCM = pic.OriginalWidthCM;
//Save the excel file.
workbook.Save("result.xlsx");

OriginalWidthInch

Gets the original width of picture, in unit of inches.

public double OriginalWidthInch { get; }

Property Value

double

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original width of the picture.
double picWidthInch = pic.OriginalWidthInch;
//Save the excel file.
workbook.Save("result.xlsx");

SignatureLine

Gets and sets the signature line

public SignatureLine SignatureLine { get; set; }

Property Value

SignatureLine

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, (string)null);
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
// Create signature line object
SignatureLine s = new SignatureLine();
s.Signer = "Simon";
s.Title = "Development";
s.Email = "simon@aspose.com";
// Assign the signature line object to Picture.
pic.SignatureLine = s;
//Save the excel file.
workbook.Save("result.xlsx");

SourceFullName

Gets or sets the path and name of the source file for the linked image.

public string SourceFullName { get; set; }

Property Value

string

Remarks

The default value is an empty string. If SourceFullName is not an empty string, the image is linked. If SourceFullName is not an empty string, but Data is null, then the image is linked and not stored in the file.

Methods

Copy(Picture, CopyOptions)

Copy the picture.

public void Copy(Picture source, CopyOptions options)

Parameters

source Picture

The source picture.

options CopyOptions

The copy options.

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
//Copy picture 1 to picture 2.You'll get two picture 1 objects that are superimposed on top of each other.
CopyOptions opt = new CopyOptions();
pic2.Copy(pic1, opt);
//Save the excel file.
workbook.Save("result.xlsx");

IsSameSetting(object)

Returns whether the shape is same.

public override bool IsSameSetting(object obj)

Parameters

obj object

Returns

bool

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
if(pic1.IsSameSetting(pic1))
{
    //two image objects are the same.
}

if(!pic1.IsSameSetting(pic2))
{
    //two image objects are not the same.
}

Move(int, int)

Moves the picture to a specified location.

public void Move(int upperLeftRow, int upperLeftColumn)

Parameters

upperLeftRow int

Upper left row index.

upperLeftColumn int

Upper left column index.

Examples

csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Set the new location of the picture
pic.Move(2, 4);
//Save the excel file.
workbook.Save("result.xlsx");

PlaceInCell()

Place this picture in the cell

public void PlaceInCell()