Setting Image Size and Position

The Picture object's bounds specify the size and position of an image. See Size, Position and Rotation in the Working with Shapes and Groups chapter earlier in this Guide for more about methods for accessing and setting the bounds of a shape. The picture is scaled to fit within the object's bounds.

For example, to set the picture size to the image's native size and center the picture on the slide, we could use the following code:

// Create a rectangle of the same dimensions as the native image size
Dimension imageSize = picture.getData().getSize();
Rectangle bounds = new Rectangle(
  (int)Units.convert(imageSize.width, Units.EMU, Units.MASTER),
  (int)Units.convert(imageSize.height, Units.EMU, Units.MASTER));

// Position the rectangle in the center of the slide
Dimension slideSize = presentation.getSlideFormat().getSize();
bounds.x = (slideSize.width - bounds.width) / 2;
bounds.y = (slideSize.height - bounds.height) / 2;

// Set the picture bounds to be the same as our new rectangle
picture.setBounds(bounds);

Page generated: 2008-01-18 02:53:28 GMT TonicPoint Builder Developer's Guide -- Version 2.3