Free Support Forum - aspose.com

Crop a picture

Is there a way to programatically crop a picture in Aspose.Slides before placing on slide?

Here is my C# solution, I clipped 8% off the height :

Bitmap bm = new System.Drawing.Bitmap(myimage);

Bitmap newimage = new Bitmap((int)(bm.Width), (int)(bm.Height * 0.92));

Graphics newgraphics = Graphics.FromImage(newimage);

newgraphics.DrawImage(bm, 0, 0, new System.Drawing.Rectangle(0, 0, (int)bm.Width, (int)(bm.Height * .92)), GraphicsUnit.Pixel);

newgraphics.Flush();

Picture pic = new Picture(pres, newimage);

int picId = pres.Pictures.Add(pic);

It’s possible to crop image before inserting of course but PowerPoint can also do it automatically.
Please check PictureFrame.Crop* properties.