Crop Image

Hi,

How to read cropped image from ppt.

regards
khushboo

Hi Khushboo,

Thank you for posting.

I have observed your comments but I am unable to understand it completely. If you want to extract images from a slide then I would like to share with you that an image is contained inside a Picture frame which is basically a shape. You can iterate through the shapes and check for the the shape if that is a picture frame, as in the code below. Also, you can find any shape as explained in this documentation article and then create a thumbnail of the shape as explained in this documentation article.

Presentation pres = new Presentation(@"D:\Test.pptx");

foreach (Slide slide in pres.Slides)
{
    foreach (IShape shape in slide.Shapes)
    {
        if (shape is PictureFrame)
        {
            //Create Thumbnail Here
        }
    }
}

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Hi,

Thanks for the reply.
I am able to read image inside shape.PictureFormat.Picture.Image.BinaryData, and cropped position inside shape.PictureFormat.CropTop.

Is there any way to read cropped image BinaryData only.

Presentation pres = new Presentation(@"D:\Test.pptx");

foreach (Slide slide in pres.Slides)
{
    foreach (IShape shape in slide.Shapes)
    {
        if (shape is PictureFrame)
        {
            var img = shape.PictureFormat.Picture.Image;
            var cropFormat = shape.PictureFormat;

            using (Stream stream = File.OpenWrite(""))
            {
                stream.Write(shape.PictureFormat.Picture.Image.BinaryData, 0, shape.PictureFormat.Picture.Image.BinaryData.Length);
            }
        }
    }
}

Hi Khushboo,

I have observed your comments and like to share with you that the cropped image is not saved as another copy of image but the original image appears in a way that it looks cropped. Now, as per your requirements you may create a thumbnail of the shape in the bounds of its appearance as explained in this documentation article.

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Hi,

Thanks for reply.
It is helpful.

Hi Khushboo,

Thank you for your kind feedback.
Please feel free to contact us if we could be of any help to you.

Best Regards,