Image Class
Represents the functionalities for using images in presentation
Inheritance
System.Object
Image
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Syncfusion.Drawing
Assembly: Syncfusion.Presentation.Base.dll
Syntax
public class Image
Constructors
Image(Stream)
Declaration
public Image(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = new Image(imageStream);
// Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 120,100,290,200);
//Save the presentation
presentation.Save("Output.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As New Image(imageStream)
' Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 120, 100, 290, 200)
'Save the presentation
presentation.Save("Output.pptx")
'close the presentation
presentation.Close()
Properties
Format
Gets the image format. Read-only.
Declaration
public ImageFormat Format { get; }
Property Value
Type | Description |
---|---|
ImageFormat | The image format. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
//Get the image format, read only
ImageFormat imageFormat = image.Format;
//Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Output.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
'Get the image format, read only
Dim imageFormat As ImageFormat = image.Format
'Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Output.pptx")
'close the presentation
presentation.Close()
Height
Gets the height of the Image. Read-only.
Declaration
public int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The height. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
//Get the size of image, it is read only
int Height = image.Height;
int width = image.Width;
//Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Output.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
'Get the size of image, it is read only
Dim Height As Integer = image.Height
Dim width As Integer = image.Width
'Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Output.pptx")
'close the presentation
presentation.Close()
ImageData
Gets the image data as byte array. Read-only.
Declaration
public byte[] ImageData { get; }
Property Value
Type | Description |
---|---|
System.Byte[] | The image data. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
//Get the image data of image
byte[] imageData = image.ImageData;
//Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(imageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Output.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
'Get the image data of image
Dim imageData As Byte() = image.ImageData
'Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(imageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Output.pptx")
'close the presentation
presentation.Close()
RawFormat
Gets the file format of the Image. Read-only.
Declaration
public ImageFormat RawFormat { get; }
Property Value
Type | Description |
---|---|
ImageFormat | The image format. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
//Get the image format, read only
ImageFormat imageFormat = image.RawFormat;
//Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Output.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
'Get the image format, read only
Dim imageFormat As ImageFormat = image.RawFormat
'Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Output.pptx")
'close the presentation
presentation.Close()
Size
Gets the width and height of the image. Read-only.
Declaration
public Size Size { get; }
Property Value
Type | Description |
---|---|
System.Drawing.Size | The size. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
//Get the size of image, it is read only
System.Drawing.Size size = image.Size;
//Set the width and height of the image
size.Width = 300;
size.Width = 200;
//Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 120,100,size.Width,size.Height);
//Save the presentation
presentation.Save("Output.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
'Get the size of image, it is read only
Dim size As System.Drawing.Size = image.Size
'Set the width and height of the image
size.Width = 300
size.Width = 200
'Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 120, 100, size.Width, size.Height)
'Save the presentation
presentation.Save("Output.pptx")
'close the presentation
presentation.Close()
Width
Gets the width of the Image. Read-only.
Declaration
public int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The width. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
//Get the size of image, it is read only
int Height = image.Height;
int width = image.Width;
// Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Output.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
'Get the size of image, it is read only
Dim Height As Integer = image.Height
Dim width As Integer = image.Width
' Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Output.pptx")
'close the presentation
presentation.Close()
Methods
Clone()
Creates an independent copy of the specified image.
Declaration
public Image Clone()
Returns
Type | Description |
---|---|
Image | The Image this method creates. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
//Clone the image
Image clonedImage = image.Clone();
// Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(clonedImage.ImageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Image.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
'Clone the image
Dim clonedImage As Image = image.Clone()
' Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(clonedImage.ImageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Image.pptx")
'close the presentation
presentation.Close()
FromFile(String)
Creates an image from the specified file.
Declaration
public static Image FromFile(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | A string that contains the name of the file from which to create the Image. |
Returns
Type | Description |
---|---|
Image | Returns the Image this method creates. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Get the image from file path
Image image = Image.FromFile(@"image.jpg");
// Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Image.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Get the image from file path
Dim image As Image = Image.FromFile("image.jpg")
' Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Image.pptx")
'close the presentation
presentation.Close()
FromStream(Stream)
Declaration
public static Image FromStream(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream |
Returns
Type | Description |
---|---|
Image | Returns the Image this method creates. |
Examples
//Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Add a slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Create an instance for image as stream
Stream imageStream = File.Open("Image.gif", FileMode.Open);
//Get the image from file path
Image image = Image.FromStream(imageStream);
// Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(new MemoryStream(image.ImageData), 300, 270, 410, 250);
//Save the presentation
presentation.Save("Image.pptx");
//close the presentation
presentation.Close();
'Create an instance of PowerPoint presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a slide to the presentation
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Create an instance for image as stream
Dim imageStream As Stream = File.Open("Image.gif", FileMode.Open)
'Get the image from file path
Dim image As Image = Image.FromStream(imageStream)
' Add the image to the slide by specifying position and size
slide.Pictures.AddPicture(New MemoryStream(image.ImageData), 300, 270, 410, 250)
'Save the presentation
presentation.Save("Image.pptx")
'close the presentation
presentation.Close()