Posts

Showing posts from August, 2022

Drawing shapes using java graphics API | Razsoft Education

Image
Shapes in java  To draw shape in java, It provides shape interface. Any class that implement the shape interface will be used to draw shapes. To draw shapes we need to pass object of the class which implements the shape interface in the draw() of fill() method of graphics object. Outline of shape is known as path.      Java has already a list of class that implement the Shape interface to draw some basic geometrical shapes. Which is defined in to two main category Rectangular shape and non Rectangular shape. We can also implement shape interface in our own class to create custom shapes.   Rectangular Shape  Rectangular shapes are those shape which Extends the RectangularShape class. The class doesn't define any geometrical shape but it provide a rectangular frame to all the class that extend it. Here is list of some class that extends the RectengularShape class                           * Rectangle2D  * RoundRectangle2D  * Arc2D   * Ellipse2D          Draw and fill  To paint any o

Accessing device coordinates in java graphics | Razsoft Education

 Java 2D API defines three level of configuration information to encapsulate conversion information from user to device coordinate. 1. Graphics Environment class :- GraphicsEnvironment class describe the collection of rendering device visible to the java application on a platform. Rendering device include screens, printers and image buffers. It also include all the fonts available to the device.  2. Graphics Device class :- GraphicsDevice class describe all the possible rendering device on the graphics environment. Such as screens or printers. 3. Graphics Configuration class :- A GraphicsConfiguration class contains all the different types of configuration supported by the graphics device. For example let a screen may have two different configuration such as 720 * 480 or 1920 * 1080 pixel resolution. We can change it's configuration as we want. Or a screen may have different color mode such as 16-bit, 32 - bit or 256 bit color mode. All such information about a device is stored in

Coordinate system of java | Graphics2D coordinate system | Razsoft Education

Image
   As we all know java follows WORA(Write Once Run Anywhere) principle. So, in this process it may encounter many different size and type of output devices. To give the same user experience to users across all devices java manages two different coordinate system.     1. User space coordinate system    2. Device space coordinate system 1. User space coordinate system :- It's a device independent coordinate system also called logical coordinate system. Which is used by developers to draw and set elements in application. It's relative to the application. In java to do all the graphical drawing we use this coordinate system.            In user space top left corner is 0,0 position. The x- coordinate goes horizontally from left to right, and y-coordinate moves from top to bottom. And a point is defined by first x - coordinate followed by y- coordinate.  2. Device space coordinate system :- It's a device dependent coordinate system. Defined by device i.e. how device manages it

Java 2D Rendering Pipeline | Rendering in java | Razsoft Education

Image
What is Rendering?                      When we draw anything on screen, it involves many step by step process to calculate where and how to produce each pixel on screen, These step by step process is known as Rendering Pipeline and process is known as Rendering .      In this process we first define our basic shapes also known as primitives(such as text, image and geometric shapes). Then these primitives' as passed to a rendering engine like Graphics2D, That perform the step by step process of rendering pipeline. Then output image is given to an output device like screen, printer or an image stored in memory.  Apart from rendering engine Graphics2D also work as a surface to draw primitives on it. Each time we draw a new primitive on surface it added on the surface. Which we can draw on a output device.  Graphics2D States :-  Graphics2D work as a state machine to draw the primitives. It manages an internal states for rendering. Untill we not change it will use it's default st

Graphics2D API an introduction to Java2D | Razsoft Education

Image
            To overcome problems with the Graphics class and to enhance some functionality. Java introduces new class called Graphics2D . Which allows to better control over graphics operations? Also java introduces a whole set of package to do 2D graphics operation including image manipulation , drawing and transformation and the package is backward compatible.                For example Java2D API has separate class for each type of basic shapes. All the shapes implements Shape interface . Also we can define our own shape by implementing shape interface in our own custom shape class.                Control the fill and line style with control on width of the line. The Stroke and Paint interface was introduced to make custom fill and drawing style.                AffineTransform allows us to linear transformation of 2D coordinates of shapes like translation , shear , rotation and scale .                A Font is defined by Glyphs , which is individual shapes to def

Computer graphics with java an introduction | Razsoft Education

Image
               Graphics is a way to represent visual element in application. Java provided us rich set of methods and class through Java2D API to deal with the graphics in java platform and application. Using AWT methods to draw and manipulated GUI interface.                Java2D comes with rich set of function to manipulate images, text, font, color, etc. It has capability to draw basic geometric shapes and curves. Java media framework allows us to work with media files and create animations. Java media framework depends upon Java2D framework for rendering purposes.                For basic drawing operation every java AWT component which is visible to screen contains a reference to graphics object, which is an object of abstract class Graphics. It comes with many useful methods to draw elements like rectangle, ellipses and lines on AWT components. To use this method we just need to override paint() method of AWT component.                In this example we are going to