Unable to read default shape background color

Hi,


I am unable to read default shape background colour from PPT file.
If I make any new PPT and add just one shape say rectangle into it and don’t update any background colour, then I am getting NOT DEFINED as fill type.

But as soon as update the background colour,I’ll get the correct fill type.


Following is the code which we are using for reading background :-

public BackgroundStyle ReadBackground(AutoShape shape)
{
var fillType = BackgroundFillType.Solid;
try
{
fillType = (BackgroundFillType)Enum.Parse(typeof (BackgroundFillType), shape.FillFormat.FillType.ToString());
}
catch (Exception ex)
{
fillType = BackgroundFillType.NotDefined;
}
if (fillType == BackgroundFillType.Solid)
{
return GetSolidBackgroundStyle(shape.CreateFillFormatEffective());
}
if (fillType == BackgroundFillType.Gradient)
{
return GetGradientBackgroundStyle(shape.CreateFillFormatEffective());
}
if (fillType == BackgroundFillType.Picture)
{
return GetImageBackgroundStyle(shape.CreateFillFormatEffective());
}
if (fillType == BackgroundFillType.Pattern)
{
return GetPatternBackgroundStyle(shape.CreateFillFormatEffective());
}
return new SolidBackgroundStyle
{
Color = new Color
{
Value = Color.FromColor(System.Drawing.Color.Transparent).Value
},
FillType = BackgroundFillType.Solid
};
}

I am also attaching a sample file so that you can also check it.

Regards
Ankit Grover

Hi Ankit Grover,


Thanks for posting in Aspose.Slides.

I have observed your requirement and suggest you to please try using following sample code on your end. It gets the color for me on my end.

public static void GetColor()
{
Presentation pres = new Presentation("D:\\Slides Data\\Shape.pptx");
ISlide slide = pres.Slides[0];
foreach (IShape shape in slide.Shapes)
{
if (shape is IAutoShape)
{
IAutoShape ashp = (IAutoShape)shape;
if (ashp.FillFormat.FillType == FillType.Solid)
{
Color col = ashp.FillFormat.SolidFillColor.Color;
}
else
{
Color col= ashp.CreateFillFormatEffective().SolidFillColor;
}
}
}
}

Best Regards,