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,
Hi Mudassir,
Do you have a link to the documentation you are referring to?
Thanks!
Paul
Hi Paul,
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,
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,
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)I manually went through the Presentation.Images and found that Presentation.Images[4] is the background image for all slides except the first one.
{
backImg = asposeSlide.Presentation.Images[4];
}
Remember from my very first post, I want the background image for a slide in a presentation.
Paul
Hi Paul,
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,
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