PointsFromImageSpaceToPageSpace(PointF[],Resolution) Method (PdfPage)
In This Topic
Converts points from image coordinate space to PDF page coordinate space taking into account the image resolution, PDF page crop box, PDF page media box and PDF page rotation.
Syntax
Parameters
- points
- Provides points, in the image's coordinate space, to convert; returns the converted points, in the PDF page's coordinate space.
- imageResolution
- Resolution of the image coordinate space.
Example
Here is an example that shows how to convert the rectangle coordinates from the image coordinate space to the PDF page coordinate space:
''' <summary>
''' Converts the rectangle from image space to page space.
''' </summary>
''' <param name="rect">Rectangle in image space.</param>
''' <param name="imageResolution">The image resolution.</param>
''' <param name="page">The PDF page.</param>
''' <returns><see cref="System.Drawing.RectangleF"/> structure in PDF page space.</returns>
Public Shared Function ConvertRectangleFromImageSpaceToPageSpace(rect As System.Drawing.RectangleF, imageResolution As Vintasoft.Imaging.Resolution, page As Vintasoft.Imaging.Pdf.Tree.PdfPage) As System.Drawing.RectangleF
' Rectangle -> PointF[]
Dim points As System.Drawing.PointF() = New System.Drawing.PointF() {rect.Location, New System.Drawing.PointF(rect.X + rect.Width, rect.Y + rect.Height)}
' ImageSpace -> PageSpace
page.PointsFromImageSpaceToPageSpace(points, imageResolution)
' Points -> RectangleF
Dim x0 As Single = System.Math.Min(points(0).X, points(1).X)
Dim y0 As Single = System.Math.Min(points(0).Y, points(1).Y)
Dim x1 As Single = System.Math.Max(points(0).X, points(1).X)
Dim y1 As Single = System.Math.Max(points(0).Y, points(1).Y)
Return New System.Drawing.RectangleF(x0, y0, x1 - x0, y1 - y0)
End Function
/// <summary>
/// Converts the rectangle from image space to page space.
/// </summary>
/// <param name="rect">Rectangle in image space.</param>
/// <param name="imageResolution">The image resolution.</param>
/// <param name="page">The PDF page.</param>
/// <returns><see cref="System.Drawing.RectangleF"/> structure in PDF page space.</returns>
public static System.Drawing.RectangleF ConvertRectangleFromImageSpaceToPageSpace(
System.Drawing.RectangleF rect,
Vintasoft.Imaging.Resolution imageResolution,
Vintasoft.Imaging.Pdf.Tree.PdfPage page)
{
// Rectangle -> PointF[]
System.Drawing.PointF[] points = new System.Drawing.PointF[] {
rect.Location,
new System.Drawing.PointF(rect.X + rect.Width, rect.Y + rect.Height) };
// ImageSpace -> PageSpace
page.PointsFromImageSpaceToPageSpace(points, imageResolution);
// Points -> RectangleF
float x0 = System.Math.Min(points[0].X, points[1].X);
float y0 = System.Math.Min(points[0].Y, points[1].Y);
float x1 = System.Math.Max(points[0].X, points[1].X);
float y1 = System.Math.Max(points[0].Y, points[1].Y);
return new System.Drawing.RectangleF(x0, y0, x1 - x0, y1 - y0);
}
Requirements
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also