com.aspose.words
Class ImageSize

java.lang.Object
    extended by com.aspose.words.ImageSize

public class ImageSize 
extends java.lang.Object

Contains information about image size and resolution.

Example:

Shows how to resize an image shape.
DocumentBuilder builder = new DocumentBuilder();

// By default, the image is inserted at 100% scale.
Shape shape = builder.insertImage(getImageDir() + "Aspose.Words.gif");

// It is easy to change the shape size. In this case, make it 50% relative to the current shape size.
shape.setWidth(shape.getWidth() * 0.5);
shape.setHeight(shape.getHeight() * 0.5);

// However, we can also go back to the original image size and scale from there, say 110%.
ImageSize imageSize = shape.getImageData().getImageSize();
shape.setWidth(imageSize.getWidthPoints() * 1.1);
shape.setHeight(imageSize.getHeightPoints() * 1.1);

builder.getDocument().save(getArtifactsDir() + "Image.ScaleImage.doc");
See Also:
ImageData.ImageSize

Constructor Summary
ImageSize(int widthPixels, int heightPixels)
           Initializes width and height to the given values in pixels. Initializes resolution to 96 dpi.
ImageSize(int widthPixels, int heightPixels, double horizontalResolution, double verticalResolution)
           Initializes width, height and resolution to the given values.
 
Property Getters/Setters Summary
intgetHeightPixels()
           Gets the height of the image in pixels.
doublegetHeightPoints()
           Gets the height of the image in points. 1 point is 1/72 inch.
doublegetHorizontalResolution()
           Gets the horizontal resolution in DPI.
doublegetVerticalResolution()
           Gets the vertical resolution in DPI.
intgetWidthPixels()
           Gets the width of the image in pixels.
doublegetWidthPoints()
           Gets the width of the image in points. 1 point is 1/72 inch.
 

Constructor Detail

ImageSize

public ImageSize(int widthPixels, int heightPixels)
Initializes width and height to the given values in pixels. Initializes resolution to 96 dpi.
Parameters:
widthPixels - Width in pixels.
heightPixels - Height in pixels.

ImageSize

public ImageSize(int widthPixels, int heightPixels, double horizontalResolution, double verticalResolution)
Initializes width, height and resolution to the given values.
Parameters:
widthPixels - Width in pixels.
heightPixels - Height in pixels.
horizontalResolution - Horizontal resolution in DPI.
verticalResolution - Vertical resolution in DPI.

Property Getters/Setters Detail

getHeightPixels

public int getHeightPixels()
Gets the height of the image in pixels.

Example:

Shows how to access and use a shape's ImageSize property.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a shape into the document which contains an image taken from our local file system
Shape shape = builder.insertImage(getImageDir() + "Aspose.Words.gif");

// If the shape contains an image, its ImageData property will be valid, and it will contain an ImageSize object
ImageSize imageSize = shape.getImageData().getImageSize();

// The ImageSize object contains raw information about the image within the shape
Assert.assertEquals(imageSize.getHeightPixels(), 200);
Assert.assertEquals(imageSize.getWidthPixels(), 200);

final double delta = 0.05;
Assert.assertEquals(imageSize.getHorizontalResolution(), 95.98d, delta);
Assert.assertEquals(imageSize.getVerticalResolution(), 95.98d, delta);

// These values are read-only
// If we want to transform the image, we need to change the size of the shape that contains it
// We can still use values within ImageSize as a reference
// In the example below, we will get the shape to display the image in twice its original size
shape.setWidth(imageSize.getWidthPoints() * 2.0);
shape.setHeight(imageSize.getHeightPoints() * 2.0);

doc.save(getArtifactsDir() + "Image.ImageSize.docx");

getHeightPoints

public double getHeightPoints()
Gets the height of the image in points. 1 point is 1/72 inch.

Example:

Shows how to resize an image shape.
DocumentBuilder builder = new DocumentBuilder();

// By default, the image is inserted at 100% scale.
Shape shape = builder.insertImage(getImageDir() + "Aspose.Words.gif");

// It is easy to change the shape size. In this case, make it 50% relative to the current shape size.
shape.setWidth(shape.getWidth() * 0.5);
shape.setHeight(shape.getHeight() * 0.5);

// However, we can also go back to the original image size and scale from there, say 110%.
ImageSize imageSize = shape.getImageData().getImageSize();
shape.setWidth(imageSize.getWidthPoints() * 1.1);
shape.setHeight(imageSize.getHeightPoints() * 1.1);

builder.getDocument().save(getArtifactsDir() + "Image.ScaleImage.doc");

getHorizontalResolution

public double getHorizontalResolution()
Gets the horizontal resolution in DPI.

Example:

Shows how to access and use a shape's ImageSize property.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a shape into the document which contains an image taken from our local file system
Shape shape = builder.insertImage(getImageDir() + "Aspose.Words.gif");

// If the shape contains an image, its ImageData property will be valid, and it will contain an ImageSize object
ImageSize imageSize = shape.getImageData().getImageSize();

// The ImageSize object contains raw information about the image within the shape
Assert.assertEquals(imageSize.getHeightPixels(), 200);
Assert.assertEquals(imageSize.getWidthPixels(), 200);

final double delta = 0.05;
Assert.assertEquals(imageSize.getHorizontalResolution(), 95.98d, delta);
Assert.assertEquals(imageSize.getVerticalResolution(), 95.98d, delta);

// These values are read-only
// If we want to transform the image, we need to change the size of the shape that contains it
// We can still use values within ImageSize as a reference
// In the example below, we will get the shape to display the image in twice its original size
shape.setWidth(imageSize.getWidthPoints() * 2.0);
shape.setHeight(imageSize.getHeightPoints() * 2.0);

doc.save(getArtifactsDir() + "Image.ImageSize.docx");

getVerticalResolution

public double getVerticalResolution()
Gets the vertical resolution in DPI.

Example:

Shows how to access and use a shape's ImageSize property.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a shape into the document which contains an image taken from our local file system
Shape shape = builder.insertImage(getImageDir() + "Aspose.Words.gif");

// If the shape contains an image, its ImageData property will be valid, and it will contain an ImageSize object
ImageSize imageSize = shape.getImageData().getImageSize();

// The ImageSize object contains raw information about the image within the shape
Assert.assertEquals(imageSize.getHeightPixels(), 200);
Assert.assertEquals(imageSize.getWidthPixels(), 200);

final double delta = 0.05;
Assert.assertEquals(imageSize.getHorizontalResolution(), 95.98d, delta);
Assert.assertEquals(imageSize.getVerticalResolution(), 95.98d, delta);

// These values are read-only
// If we want to transform the image, we need to change the size of the shape that contains it
// We can still use values within ImageSize as a reference
// In the example below, we will get the shape to display the image in twice its original size
shape.setWidth(imageSize.getWidthPoints() * 2.0);
shape.setHeight(imageSize.getHeightPoints() * 2.0);

doc.save(getArtifactsDir() + "Image.ImageSize.docx");

getWidthPixels

public int getWidthPixels()
Gets the width of the image in pixels.

Example:

Shows how to access and use a shape's ImageSize property.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a shape into the document which contains an image taken from our local file system
Shape shape = builder.insertImage(getImageDir() + "Aspose.Words.gif");

// If the shape contains an image, its ImageData property will be valid, and it will contain an ImageSize object
ImageSize imageSize = shape.getImageData().getImageSize();

// The ImageSize object contains raw information about the image within the shape
Assert.assertEquals(imageSize.getHeightPixels(), 200);
Assert.assertEquals(imageSize.getWidthPixels(), 200);

final double delta = 0.05;
Assert.assertEquals(imageSize.getHorizontalResolution(), 95.98d, delta);
Assert.assertEquals(imageSize.getVerticalResolution(), 95.98d, delta);

// These values are read-only
// If we want to transform the image, we need to change the size of the shape that contains it
// We can still use values within ImageSize as a reference
// In the example below, we will get the shape to display the image in twice its original size
shape.setWidth(imageSize.getWidthPoints() * 2.0);
shape.setHeight(imageSize.getHeightPoints() * 2.0);

doc.save(getArtifactsDir() + "Image.ImageSize.docx");

getWidthPoints

public double getWidthPoints()
Gets the width of the image in points. 1 point is 1/72 inch.

Example:

Shows how to resize an image shape.
DocumentBuilder builder = new DocumentBuilder();

// By default, the image is inserted at 100% scale.
Shape shape = builder.insertImage(getImageDir() + "Aspose.Words.gif");

// It is easy to change the shape size. In this case, make it 50% relative to the current shape size.
shape.setWidth(shape.getWidth() * 0.5);
shape.setHeight(shape.getHeight() * 0.5);

// However, we can also go back to the original image size and scale from there, say 110%.
ImageSize imageSize = shape.getImageData().getImageSize();
shape.setWidth(imageSize.getWidthPoints() * 1.1);
shape.setHeight(imageSize.getHeightPoints() * 1.1);

builder.getDocument().save(getArtifactsDir() + "Image.ScaleImage.doc");

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.