Skip to content

Easy Way To Draw Line On Image in JAVA

Published
Reading time
1 min read
Views
1.6k views
How to Add ArrayList into Another ArrayList Java Code

In this article you will learn how to draw line on an image in JAVA language. This is very easy way. You also can store this image in your System.

BufferedImage img = new BufferedImage(600, 315, BufferedImage.TYPE_INT_RGB );
//draw line verticle
for(int vl = 0; vl < 315; vl++)
{
     img.setRGB(300, vl, Color.WHITE.getRGB() );
}
       
//draw line horizontal
for(int vh = 0; vh < 600; vh++)
{
    img.setRGB(vh, 157, Color.WHITE.getRGB() );
}
String path = System.getProperty("user.home");
ImageIO.write(img, "PNG", new File(path+"\\Documents\\NetBeansProjects\\img.png"));

Questions & comments

Did this work for you, or did you hit a different error? Ask below and we will help.

Comments are reviewed before they appear.

More like this

More in Programming

Programming

How To Read Data From .txt File Java

In this article you will learn Read Data From .txt File in Java Language Line by Line. This is very easy Step by Step program is written below. String str = null; try { B…

Programming

Draw sine function with PHP code on an image.

Now we learn how to draw a sine function in PHP. It is very simple and easy to draw sine function in PHP language. This function will generate a sine wave on image. Watch…

Programming

PHP code to draw cos function on image

Today i will tell you how to draw cos function in PHP. This is very simple task to draw a cosine function with PHP code. These are functions of Mathematics and used in Nu…

Programming

PHP code to draw a parabola and create image

Hello Friends today i will discuss how to draw a parabola with PHP code and create an image. We will draw this parabola with standard equation. <?php $x = 400; $y = 400;…