We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Scale image in picture frame

Hi,


I’m currently adding an image to a slide using the following code :

Image img = Image.FromFile(filename);
ImageEx image = presentation.Images.AddImage(img);
slide.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, shape.X, shape.Y, image.Width, image.Height, image);

I would like to scale the image to to fit a certain area rather than adding a picture box of the image size.

Is this possible? If so how?

Cheers,

Neal

Hi Neal,


Thanks for considering Aspose.Slides.

One can set the desired image width and height for the picture frame to fill any area on the slide. Please use the code snippet given below to achieve the goal. I have used the maximum slide width and height as height and width of picture frame. You can set any value less than this to serve the purpose.


//Instantiate PrseetationEx class that represents the PPTX
PresentationEx pres = new PresentationEx();

//Get the first slide
SlideEx sld = pres.Slides[0];

//Instantiate the ImageEx class
System.Drawing.Image img = (System.Drawing.Image)new Bitmap(“d:\Change Image\Tulips.jpg”);
ImageEx imgx = pres.Images.AddImage(img);

//Add Picture Frame with height and width equivalent of Picture
int imageWidth, imageHeight;
imageWidth = 720;//Max slide width
imageHeight = 540;//Max sllide height
// sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 50, 150, imageWidth, imageHeight, imgx);
sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 0, 0, imageWidth, imageHeight, imgx);

//Write the PPTX file to disk
pres.Write(“d:\Change Image\RectPicFrame.pptx”);


Many Thanks,