get_opaque_bounds_in_pixels method
Contents
[
Hide
]get_opaque_bounds_in_pixels(scale, dpi)
Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
def get_opaque_bounds_in_pixels(self, scale: float, dpi: float):
...
Parameter | Type | Description |
---|---|---|
scale | float | The zoom factor (1.0 is 100%). |
dpi | float | The resolution to convert from points to pixels (dots per inch). |
Remarks
This method converts NodeRendererBase.opaque_bounds_in_points into rectangle in pixels and it is useful when you want to create a bitmap for rendering the shape with only opaque part of the shape.
Returns
The opaque rectangle of the shape in pixels.
get_opaque_bounds_in_pixels(scale, horizontal_dpi, vertical_dpi)
Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
def get_opaque_bounds_in_pixels(self, scale: float, horizontal_dpi: float, vertical_dpi: float):
...
Parameter | Type | Description |
---|---|---|
scale | float | The zoom factor (1.0 is 100%). |
horizontal_dpi | float | The horizontal resolution to convert from points to pixels (dots per inch). |
vertical_dpi | float | The vertical resolution to convert from points to pixels (dots per inch). |
Remarks
This method converts NodeRendererBase.opaque_bounds_in_points into rectangle in pixels and it is useful when you want to create a bitmap for rendering the shape with only opaque part of the shape.
Returns
The opaque rectangle of the shape in pixels.
Examples
Shows how to measure and scale shapes.
doc = aw.Document(file_name=MY_DIR + 'Office math.docx')
office_math = doc.get_child(aw.NodeType.OFFICE_MATH, 0, True).as_office_math()
renderer = aw.rendering.OfficeMathRenderer(office_math)
# Verify the size of the image that the OfficeMath object will create when we render it.
self.assertAlmostEqual(122, renderer.size_in_points.width, delta=0.25)
self.assertAlmostEqual(13, renderer.size_in_points.height, delta=0.15)
self.assertAlmostEqual(122, renderer.bounds_in_points.width, delta=0.25)
self.assertAlmostEqual(13, renderer.bounds_in_points.height, delta=0.15)
# Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
self.assertAlmostEqual(122, renderer.opaque_bounds_in_points.width, delta=0.25)
self.assertAlmostEqual(14.2, renderer.opaque_bounds_in_points.height, delta=0.1)
# Get the shape size in pixels, with linear scaling to a specific DPI.
bounds = renderer.get_bounds_in_pixels(scale=1, dpi=96)
self.assertEqual(163, bounds.width)
self.assertEqual(18, bounds.height)
# Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
bounds = renderer.get_bounds_in_pixels(scale=1, horizontal_dpi=96, vertical_dpi=150)
self.assertEqual(163, bounds.width)
self.assertEqual(27, bounds.height)
# The opaque bounds may vary here also.
bounds = renderer.get_opaque_bounds_in_pixels(scale=1, dpi=96)
self.assertEqual(163, bounds.width)
self.assertEqual(19, bounds.height)
bounds = renderer.get_opaque_bounds_in_pixels(scale=1, horizontal_dpi=96, vertical_dpi=150)
self.assertEqual(163, bounds.width)
self.assertEqual(29, bounds.height)
See Also
- module aspose.words.rendering
- class NodeRendererBase