Java examples for 2D Graphics:Line
draw Flat Scan Line
//package com.java2s; import java.awt.image.BufferedImage; public class Main { private static void drawFlatScanLine(int y, int x0, int x1, BufferedImage image, int width, int rgb) { if (x0 == x1) { if (x0 > 0 && x0 < width) image.setRGB(x0, y, rgb); } else {//from ww w. j av a2 s . c o m if (x1 < x0) { int temp = x1; x1 = x0; x0 = temp; } int leftExtent = x0 < 0 ? 0 : x0; int rightExtent = x1 > width ? width : x1; for (int loop = leftExtent; loop < rightExtent; ++loop) { image.setRGB(loop, y, rgb); } } } }