Articles in this section
Category / Section

How to remove the crop from image in ASP.NET Core Presentation using C#?

3 mins read

Syncfusion PowerPoint is a .NET PowerPoint library used to create, read, and edit PowerPoint presentation programmatically without Microsoft PowerPoint or interop dependencies. Using this library, you can remove the crop from image in Presentation using C#.

Steps to remove the crop from image in Presentation using C#

Step 1: Create a new .NET Core console application project.

.NET Core console application project

Step 2: Install the Syncfusion.PresentationRenderer.Net.Core NuGet package as a reference to your project from NuGet.org.

Install Syncfusion.PresentationRenderer.Net.Core NuGet package

Note: Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

Step 3: Include the following namespaces in Program.cs file.

using Syncfusion.Presentation;

Step 4: Include the below code snippet in Program.cs to remove the crop from image in Presentation.

//Open an existing PowerPoint Presentation.
using (FileStream inputStream = new FileStream("Sample.pptx", FileMode.Open, FileAccess.Read))
{
   using (IPresentation pptxDoc = Presentation.Open(inputStream))
   {
       //Retrieve the first slide from the Presentation.
       ISlide slide = pptxDoc.Slides[0];
       //Retrieve the first picture from the slide.
       IPicture picture = slide.Pictures[0];
       //Remove the crop from image.
       SKBitmap bitmap = SKBitmap.Decode(new MemoryStream(picture.ImageData));
       //Reset the picture with original width and height.
       picture.Crop.Width = PixelToPoint(bitmap.Width);
       picture.Crop.Height = PixelToPoint(bitmap.Height);
       picture.Crop.ContainerWidth = PixelToPoint(bitmap.Width);
       picture.Crop.ContainerHeight = PixelToPoint(bitmap.Height);
       picture.Crop.OffsetX = 0;
       picture.Crop.OffsetY = 0;
       //Save the PowerPoint Presentation as stream.
       using (FileStream outputStream = new FileStream("Output.pptx", FileMode.Create))
       {
           pptxDoc.Save(outputStream);
       }
   }        
}

/// <summary>
/// Convert a value from pixel to point.
/// </summary>
/// <param name="value">The value in pixel which needs to be converted to point.</param>
/// <returns>The value converted to point.</returns>
private int PixelToPoint(double value)
{
   return Convert.ToInt32((value * 72) / 96);
}

A complete working sample to remove the crop from image in Presentation using C# can be downloaded from GitHub.

By executing the program, you will get the PowerPoint presentation as follows.

Output of removed crop in Presentation

Conclusion

I hope you enjoyed learning about how to remove the crop from image in ASP.NET Core Presentation using C#.

You can refer to our ASP.NET Core Presentation feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core Presentation example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied