How To Draw On A Bufferedimage In Java
Java BufferedImage Class
Java BufferedImage
form is a subclass of Image class. Information technology is used to handle and manipulate the image data. A BufferedImage
is made of ColorModel of prototype data. All BufferedImage
objects accept an upper left corner coordinate of (0, 0).
Constructors
This class supports three types of constructors.
The first constructor constructs a new BufferedImage
with a specified ColorModel and Raster.
BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?,?> properties)
The second constructor constructs a BufferedImage
of one of the predefined image types.
BufferedImage(int width, int top, int imageType)
The third constructor constructs a BufferedImage
of one of the predefined image types: TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.
BufferedImage(int width, int summit, int imageType, IndexColorModel cm)
Sr.No | Method & Description |
---|---|
1 | copyData(WritableRaster outRaster) It computes an arbitrary rectangular region of the |
2 | getColorModel() Information technology returns object of course ColorModel of an image. |
3 | getData() Information technology returns the image equally i large tile. |
4 | getData(Rectangle rect) It computes and returns an arbitrary region of the |
5 | getGraphics() This method returns a Graphics2D, retains backwards compatibility. |
vi | getHeight() It returns the elevation of the |
seven | getMinX() It returns the minimum ten coordinate of this |
8 | getMinY() It returns the minimum y coordinate of this |
9 | getRGB(int x, int y) It returns an integer pixel in the default RGB colour model (TYPE_INT_ARGB) and default sRGB colorspace. |
10 | getType() It returns the image type. |
Example
The post-obit example demonstrates the utilise of coffee BufferedImage
class that draw some text on the screen using Graphics Object −
import java.awt.Graphics; import java.awt.Image; import coffee.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; public class Examination extends JPanel { public void pigment(Graphics chiliad) { Prototype img = createImageWithText(); 1000.drawImage(img, twenty,20,this); } individual Prototype createImageWithText() { BufferedImage bufferedImage = new BufferedImage(200,200,BufferedImage.TYPE_INT_RGB); Graphics g = bufferedImage.getGraphics(); g.drawString("www.tutorialspoint.com", 20,20); g.drawString("www.tutorialspoint.com", xx,xl); g.drawString("www.tutorialspoint.com", twenty,60); k.drawString("www.tutorialspoint.com", twenty,80); k.drawString("world wide web.tutorialspoint.com", 20,100); return bufferedImage; } public static void main(String[] args) { JFrame frame = new JFrame(); frame.getContentPane().add(new Test()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); } }
Output
When y'all execute the given lawmaking, the following output is seen −
Useful Video Courses
Video
Video
Video
Video
Video
Source: https://www.tutorialspoint.com/java_dip/java_buffered_image.htm
Posted by: ramosbuttle.blogspot.com
0 Response to "How To Draw On A Bufferedimage In Java"
Post a Comment