Working with Coordinate System Transformations

Global Transformation in Java

To globally transform a scene in Java, follow these steps:

  • Create an instance of the Bitmap class.
  • Initialize a new object of the Graphics class with this bitmap object.
  • Use the rotateTransform() method of the Graphics object to specify the rotation angle.
  • Draw the shapes with global transformation.
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA
import com.aspose.drawing.*;
Bitmap bitmap = new Bitmap(1000, 800, com.aspose.drawing.imaging.Format32bppPArgb);
Graphics graphics = Graphics.fromImage(bitmap);
graphics.clear(Color.getGray());
// Set a transformation that applies to every drawn item:
graphics.rotateTransform(15);
Pen pen = new Pen(Color.getBlue(), 2);
graphics.drawEllipse(pen, 300, 300, 400, 200);
bitmap.save("GlobalTransformation.png");

Global Transformation

Local Transformation of in Java

To locally transform an object in Java, follow these steps:

  • Create an instance of the Bitmap class.
  • Initialize a new object of the Graphics class with this bitmap object.
  • Create a shape such as Ellipse.
  • Define a Matrix object with the desired transformation.
  • Apply the matrix to the defined object.
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA
import com.aspose.drawing.*;
import com.aspose.drawing.drawing2d;
Bitmap bitmap = new Bitmap(1000, 800, com.aspose.drawing.imaging.Format32bppPArgb);
Graphics graphics = Graphics.fromImage(bitmap);
graphics.clear(Color.getGray());
GraphicsPath path = new GraphicsPath();
path.addEllipse(300, 300, 400, 200);
// Set a transformation that applies to the specific path to be drawn:
Matrix matrix = new Matrix();
matrix.rotateAt(45, new Point(500, 400));
path.transform(matrix);
Pen pen = new Pen(Color.getBlue(), 2);
graphics.drawPath(pen, path);
bitmap.save("LocalTransformation.png");

Local Transformation

Matrix Transformation of a Path in Java

To perform a matrix transformation on a path in Java, follow these steps:

  • Create an instance of the Bitmap class.
  • Initialize a new object of the Graphics class with this bitmap object.
  • Create a shape such as a Rectangle.
  • Define the Matrix Transformation using the Matrix class.
  • Apply the transformation to a defined rectangle.

Matrix Transformation

Page Transformation in Java

To perform a page transformation of a scene in Java, follow these steps:

  • Create an instance of the Bitmap class.
  • Initialize a new object of the Graphics class with this bitmap object.
  • Set the GraphicsUnit for the Graphics class object.
  • Draw a shape such as a Rectangle.
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA
import com.aspose.drawing.*;
Bitmap bitmap = new Bitmap(1000, 800, com.aspose.drawing.imaging.Format32bppPArgb);
Graphics graphics = Graphics.fromImage(bitmap);
graphics.clear(Color.getGray());
// Set the transformation that maps page coordinates to device coordinates:
graphics.pageUnit = GraphicsUnit.Inch;
Pen pen = new Pen(Color.getBlue(), 0.1f);
graphics.drawRectangle(pen, 1, 1, 1, 1);
bitmap.save("PageTransformation.png");

Page Transformation

Applying Different Units of Measurement in Java

To apply different units of measurement to different objects in a scene in Java, follow these steps:

  • Create an instance of the Bitmap class.
  • Initialize a new object of the Graphics class with this bitmap object.
  • Set the pageUnit properties for the Graphics class object.
  • Draw shapes such as rectangles.
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA
import com.aspose.drawing.*;
Bitmap bitmap = new Bitmap(1000, 800, com.aspose.drawing.imaging.Format32bppPArgb);
Graphics graphics = Graphics.fromImage(bitmap);
graphics.clear(Color.getGray());
// 1 point is 1/72 inch.
graphics.pageUnit = GraphicsUnit.Point;
graphics.drawRectangle(new Pen(Color.getRed(), 36f), 72, 72, 72, 72);
// 1 mm is 1/25.4 inch.
graphics.pageUnit = GraphicsUnit.Millimeter;
graphics.drawRectangle(new Pen(Color.getGreen(), 6.35f), 25.4f, 25.4f, 25.4f, 25.4f);
graphics.pageUnit = GraphicsUnit.Inch;
graphics.drawRectangle(new Pen(Color.getBlue(), 0.125f), 1, 1, 1, 1);
bitmap.save("UnitsOfMeasure.png");

Units of Measure

World Transformation in Java

To apply world transformation in Java, follow these steps:

// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA
import com.aspose.drawing.*;
Bitmap bitmap = new Bitmap(1000, 800, com.aspose.drawing.imaging.Format32bppPArgb);
Graphics graphics = Graphics.fromImage(bitmap);
graphics.clear(Color.getGray());
// Set the transformation that maps world coordinates to page coordinates:
graphics.translateTransform(500, 400);
Pen pen = new Pen(Color.getBlue(), 2);
graphics.drawRectangle(pen, 0, 0, 300, 200);
bitmap.save("WorldTransformation.png");

World Transformation