Free Support Forum - aspose.com

Images getting cut-off on edges with GetThumbnail method

Hi. I am using the GetThumbnail method to extract all shapes as images out of a presentation.
What is happening is that all images are getting cut-off at the right-side and bottom edges by about 1-2 pixels. See attached zip file that contains the ppt file that I used and the images extracted out of it.

Here’s my code:
Presentation pres = new Presentation(“Shapes.ppt”);

foreach (Slide slide in pres.Slides)
{
//Iterate all shapes on a slide and create thumbnails
Shapes shapes = slide.Shapes;

int i = 0;
foreach (Shape shape in shapes)
{
i++;
//Getting the thumbnail image of the shape

Image img = slide.GetThumbnail(new object[] { shape }, 1.0, 1.0, shape.ShapeRectangle);

Bitmap bmp = new Bitmap(img);

bmp.MakeTransparent(Color.White);

//Saving the thumbnail image in gif format

bmp.Save(“Shape” + i + “.png”, ImageFormat.Png);

}
}

Please let me know if this is a known bug, and if you have a fix for it.
Thanks,
Aseem
DominKnow Inc

Dear Aseem,

Then you should increase the dimension (x, y, height, width) of bounding rectangle.

Can you please tell how with a code example?

For example

int OFFSET = 25;

System.Drawing.Rectangle BoundingRect=new System.Drawing.Rectangle(shape.X - OFFSET, shape.Y - OFFSET, shape.Width + 2*OFFSET, shape.Height + 2*OFFSET);

Image img = slide.GetThumbnail(new object[] { shape }, 1.0, 1.0, BoundingRect);

Thanks. But is this Offset of 25 a constant value that works on most AutoShapes, or is it a variable that should be calculated for each shape? If so, how is it calculated?
Thanks,
Aseem

No, actually, it is a random number that I used to enclose the entire shape.


Ok. But can you recommend the best way to calculate that offset?

I think the best way is use width of line as offset.
shape.LineFormat.Width