print Image Blue Raster - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

print Image Blue Raster

Demo Code


import java.awt.Image;
import java.awt.image.BufferedImage;

public class Main{
    public static void printImageBlueRaster(BufferedImage image) {
        int width = image.getWidth();
        int[] imgData = new int[width];

        System.out.print("     ||");
        for (int x = 0; x < width; x++) {
            System.out.print(Objected2DUtils.extendString(x, "0", 3) + "|");
        }//  w  w w.  j a va 2 s  .  c  om
        System.out.print("\n-------");
        for (int x = 0; x < width; x++) {
            System.out.print("----");
        }
        System.out.print("\n");

        for (int y = 0; y < image.getHeight(); y++) {
            // fetch a line of data from each image
            image.getRGB(0, y, width, 1, imgData, 0, 1);

            // apply the mask
            System.out.print(" " + Objected2DUtils.extendString(y, "0", 3)
                    + " ||");

            for (int x = 0; x < width; x++) {
                String string = String.valueOf(((imgData[x] >> 8) & 0xFF));

                while (string.length() < 3) {
                    string = "0" + string;
                }

                System.out.print("" + string + "|");
            }

            System.out.print("\n");
        }
    }
    public static String extendString(Object stringO, String extender,
            int length) {
        String string = String.valueOf(stringO);

        while (string.length() < length) {
            string = extender + string;
        }

        return string;
    }
}

Related Tutorials