Point & PointF
IronDrawing introduces two new classes: IronSoftware.Drawing.Point
and IronSoftware.Drawing.PointF
. These classes are used to represent an ordered pair of double-x and double-y coordinates, defining a point in a two-dimensional plane, which is useful for image processing. Similar classes are present in other image libraries such as System.Drawing
, SixLabors.ImageSharp
, SkiaSharp
, and Microsoft.Maui.Graphics
. The difference between the Point
and PointF
classes lies in the type of value accepted as a parameter in the constructor of the Point
and PointF
objects.
Instantiating a new Point
or PointF
object is straightforward, requiring only two properties to be set: X and Y values that make up the coordinates of the point.
Here's an example illustrating how to instantiate these objects:
// Import the necessary namespace
using IronSoftware.Drawing;
public class DrawingExample
{
public static void Main()
{
// Creating a Point object with System.Double values
Point point = new Point(10.5, 25.3);
// Creating a PointF object with System.Single values (float)
PointF pointF = new PointF(10.5f, 25.3f);
// Output the coordinates to the console
System.Console.WriteLine($"Point coordinates: X = {point.X}, Y = {point.Y}");
System.Console.WriteLine($"PointF coordinates: X = {pointF.X}, Y = {pointF.Y}");
}
}
// Import the necessary namespace
using IronSoftware.Drawing;
public class DrawingExample
{
public static void Main()
{
// Creating a Point object with System.Double values
Point point = new Point(10.5, 25.3);
// Creating a PointF object with System.Single values (float)
PointF pointF = new PointF(10.5f, 25.3f);
// Output the coordinates to the console
System.Console.WriteLine($"Point coordinates: X = {point.X}, Y = {point.Y}");
System.Console.WriteLine($"PointF coordinates: X = {pointF.X}, Y = {pointF.Y}");
}
}
' Import the necessary namespace
Imports IronSoftware.Drawing
Public Class DrawingExample
Public Shared Sub Main()
' Creating a Point object with System.Double values
Dim point As New Point(10.5, 25.3)
' Creating a PointF object with System.Single values (float)
Dim pointF As New PointF(10.5F, 25.3F)
' Output the coordinates to the console
System.Console.WriteLine($"Point coordinates: X = {point.X}, Y = {point.Y}")
System.Console.WriteLine($"PointF coordinates: X = {pointF.X}, Y = {pointF.Y}")
End Sub
End Class
In the code snippet above:
Point
is instantiated usingSystem.Double
values to set thex
andy
properties of thePoint
object.PointF
is instantiated usingSystem.Single
values (float values) for the same purpose.
Both IronSoftware.Drawing.Point
and IronSoftware.Drawing.PointF
classes share the same functionality and methods. Using System.Double
is often preferred due to its higher accuracy, accepting larger decimal point values, and representing double precision as a 64-bit floating-point type. On the other hand, System.Single
is a 32-bit floating-point type, providing lower precision compared to System.Double
. As a result, it is recommended to use IronSoftware.Drawing.Point
rather than IronSoftware.Drawing.PointF
.