Back to Devexpress

Picture.ChangeImage(SpreadsheetImageSource, ImageReplacementMode) Method

officefileapi-devexpress-dot-spreadsheet-dot-picture-dot-changeimage-x28-devexpress-dot-spreadsheet-dot-spreadsheetimagesource-devexpress-dot-spreadsheet-dot-imagereplacementmode-x29.md

latest3.7 KB
Original Source

Picture.ChangeImage(SpreadsheetImageSource, ImageReplacementMode) Method

Replaces the current worksheet image with a different image.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void ChangeImage(
    SpreadsheetImageSource imageSource,
    ImageReplacementMode mode = ImageReplacementMode.Stretch
)
vb
Sub ChangeImage(
    imageSource As SpreadsheetImageSource,
    mode As ImageReplacementMode = ImageReplacementMode.Stretch
)

Parameters

NameTypeDescription
imageSourceSpreadsheetImageSource

An object used to load the new image.

|

Optional Parameters

NameTypeDefaultDescription
modeImageReplacementModeStretch

Specifies how to resize the new image. If omitted, Stretch mode is used.

|

Remarks

The example below demonstrates how to replace an existing picture in a worksheet and insert a new picture at the same position. The mode parameter is set to KeepAspectRatio. This mode scales the new picture to fit the largest dimension (width or height) of the original picture. The other dimension is calculated based on the aspect ratio of the inserted image.

csharp
using DevExpress.Spreadsheet;
// ...

// Set measurement unit to inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;
Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;
// Insert a picture from a file.
// The picture's top left corner is in the "B2" cell.
var picture = worksheet.Pictures.AddPicture(SpreadsheetImageSource.FromFile(@"Images\DevAvLogo.png"), 
  worksheet.Cells["B2"]);
// Specify the picture size.
picture.Width = 0.5f;
picture.Height = 1f;
// Replace the picture.
picture.ChangeImage(SpreadsheetImageSource.FromFile(@"Images\DevExpressLogo.png"), 
  ImageReplacementMode.KeepAspectRatio);
vb
Imports DevExpress.Spreadsheet
' ...

' Set measurement unit to inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch
Dim worksheet As Worksheet = workbook.Worksheets.ActiveWorksheet
' Insert a picture from a file.
' The picture's top left corner is in the "B2" cell.
Dim picture As Picture = worksheet.Pictures.AddPicture(SpreadsheetImageSource.FromFile("Images\DevAvLogo.png"),
                                                      worksheet.Cells("B2"))
' Specify the picture size.
picture.Width = 0.5F
picture.Height = 1F
' Replace the picture.
picture.ChangeImage(SpreadsheetImageSource.FromFile("Images\DevExpressLogo.png"), 
                                                    ImageReplacementMode.KeepAspectRatio)

See Also

Picture Interface

Picture Members

DevExpress.Spreadsheet Namespace