Support for setting Hide Background graphics property (C# .NET)

Hello,

I’m writing a C# app where I’d like to show and allow the user to change the background of a slide. The slide has a LayoutType associated with a Master. How do I get the background image to display?

Thanks for any assistance,
Paul

Hi Paul,


I have observed the requirements shared and request you to please visit the documentation link for your kind reference in this regard. Please share, if I may help you further in this regard.

Many Thanks,

Hi Mudassir,

Do you have a link to the documentation you are referring to?

Thanks!
Paul

Hi Paul,


I am sorry for your inconvenience. You can please refer to Setting Image as background article. Please share, if I may help you further in this regard.

Many Thanks,

Thank you for your response. However, I’m looking for how to ‘get’ the background image for a slide when there are several masters identified for a presentation. I’m using Aspose Slides for .Net and it doesn’t seem to have the getBackground() method that is found in Java:

BackgroundEx bkg = pres1.getSlides().get(0).getBackground();

Any guidance is appreciated.
Paul

Hi Paul,


I have observed the sample code line shared by you and it seems you are using old API that is no longer supported. Unfortunately, we don’t have any live reference material for that and also its support is not available now. I suggest you to please download the old documentation from this link and look for article Extracting images from Presentation Shapes. You will find an example to extract the image from there.

Many Thanks,

Thank you for your response, Mudassir.

I want the background image for a slide.

I’m using Aspose.Slides for .Net. version 15.1.

Paul

Hi Paul,

I have added an article for extracting image from slide shape as well as from slide background over this documentation link. I hope this will be helpful to serve the purpose on your end. Please share, if I may help you further in this regard.

Many Thanks,

Thank you for your response, Mudassir.

However, your article provides a Java solution. I’m using C# and ISlide does contain a getBackground() method. Could you supply a solution in C#?

Thanks
Paul

Here is my current attempt in C#. It’s is able to get the background image for the first slide but not for subsequent slides.

IPPImage backImg = null;

if (asposeSlide.Background.FillFormat.FillType == FillType.Picture)
{
backImg = asposeSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
}
else
{
if (asposeSlide.LayoutSlide.Background.FillFormat.FillType == FillType.Picture)
{
backImg = asposeSlide.LayoutSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
}
}

if (backImg != null)
{
BackgroundImage = backImg.BinaryData;
}

Hi Paul,

I shared the Java link as in one of your previous posts you shared the java sample. Please visit this documentation link for .NET related sample of the same implementation.

Many Thanks,

Hi Mudassir,
Thank you for your reply. I found another person with the same question as me and your answer to that question was the solution I was looking for. See the question here:

How to read Master slide background?

UNFORTUNATELY…my PPTX file has 3 masters and all of them return ‘NotDefined’ with this code:

master.Background.FillFormat.FillType

There must be a bug!

Paul

Hi Paul,

I like to share that the link that you have referred is extracting the image from the slide background that is added either in slide, its layout slide or its master slide. If you are having issue on your end then please share the sample presentation with multiple masters in it that is failing to extract image. I will investigate that further to help you out.

Many Thanks,

Hi Mudassir,

Thank you for your reply. Attached should be the PowerPoint presentation that I’m working with. I can get the background image for the first slide by accessing its LayoutSlide but not for the other slides.

Paul

Hi Paul,


I have observed the presentation file shared by you and like to share that the issue is not with Aspose.Slides while extracting the images. You can treat the Master and Layout slides similar to normal slides and extract images from all shapes and background. I have shared the logic that traverse through every slide, its respective layout slide and respective master slide to extract background and shapes images from that. Please note here that i am traversing through normal slides. So, if your slides are using all layout slides inside used master than all layout slides will be traversed. Otherwise, only those layout slides will be traversed for which a slide exist in presentation. You can also traverse through masters and then every layout slide inside the master for extracting images. I have shared both mechanisms for your reference. I hope this will be helpful now.

Many Thanks,

Hi Mudassir,

Thank you for your reply. I reviewed your attached code. Essentially, it does this:

if (asposeSlide.Background.FillFormat.FillType == FillType.Picture)
{
backImg = asposeSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
}
else if (asposeSlide.LayoutSlide.Background.FillFormat.FillType == FillType.Picture)
{
backImg = asposeSlide.LayoutSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
}
else
{
backImg = asposeSlide.LayoutSlide.MasterSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
}

If you try this code with the presentation I sent earlier you will see that backImg is null for all slides in a presentation except the first slide. As a temporary fix I’ve added this code at the end:

if(backImg == null)
{
backImg = asposeSlide.Presentation.Images[4];
}
I manually went through the Presentation.Images and found that Presentation.Images[4] is the background image for all slides except the first one.

Remember from my very first post, I want the background image for a slide in a presentation.

Paul

Hi Paul,


I have observed the sample code referred by you and it seems to be one that was shared earlier by me. Have you used and gone through the sample code that I have shared in my last post. Please download that from here. I don’t see the specified implementation in the mentioned attachment link file. I request you to please observe my comments in my last post as well.

Many Thanks,

Hi Mudassir,
Thank you for your reply. I wrote a simple WPF C# program that writes to the Console whether or not the background image for a slide is found. You will see that the background image for the first slide is found but the background image for slides 2-8 are not found. Attached is the pptx file I’m using to test Aspose.Slides.
Thank you.
Paul

private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.DefaultExt = “.ppt”;
openFileDialog.Filter = “PowerPoint Files (.ppt, .pptx)|.ppt;.pptx”;
if (openFileDialog.ShowDialog() == true)
{
string presentationPath = openFileDialog.FileName;

Aspose.Slides.Presentation pres = new Aspose.Slides.Presentation(presentationPath);

Aspose.Slides.IPPImage backImg = null;

foreach (Aspose.Slides.Slide sl in pres.Slides)
{
backImg = null;

if (sl.Background.FillFormat.FillType == Aspose.Slides.FillType.Picture)
{
backImg = sl.Background.FillFormat.PictureFillFormat.Picture.Image;
}
else if (sl.LayoutSlide.Background.FillFormat.FillType == Aspose.Slides.FillType.Picture)
{
backImg = sl.LayoutSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
}
else
{
backImg = sl.LayoutSlide.MasterSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
}

if (backImg == null)
{
Console.WriteLine("Background image NOT FOUND for slide: " + sl.SlideNumber.ToString());
}
else
{
Console.WriteLine("Background image FOUND for slide: " + sl.SlideNumber.ToString());
}
}
}
}

Hi Paul,


I have worked with the presentation file and request you to please try using the attached sample code to serve the purpose. To verify the missing images form slide 2 and 8, I have deliberately made a small change in it to extract the images from slide 2 and 8 alone. You can remove the if condition once you are satisfied with image extraction of slide 2. In my opinion, It is working as expected and extracting the images. Please try using the approach shared by me in your application. The extracted images are also attached for your kind reference.

//Accessing the presentation
Presentation pres = new Presentation(path + “General Nurse Orientation_4910010 Final.pptx”);
int slideIndex=0;
for (int i = 0; i < pres.Slides.Count; i++)
{
if (i == 1 || i == 7)
{
//Accessing the first slide
ISlide sl = pres.Slides[i];
ExtractMasterSlideImages(sl.LayoutSlide.MasterSlide, “Master”, slideIndex);
ExtractLayoutSlideImages(sl.LayoutSlide, “Layout”, slideIndex);
ExtractSlideImages(sl, “Slide”, slideIndex);

}
slideIndex++;
}

Many Thanks,

Many Thanks,

Hi Mudassir,
Thank you for your reply. In PowerPoint a user can right-click a slide and select “Format Background”. On the dialog that appears the user can select “Hide background graphics”. Checking this option will prevent layout slide and master slide shapes from displaying on the slide.

With Aspose.Slides, is it possible to know if the user has checked “Hide background graphics”?

Thanks,
Paul