Monday, July 23, 2007

DOES A PICTURE SAY A THOUSAND WORDS 3?

I won't bore you any longer with steps to take, you already know them. After the First and Second blog on this topic, this here is the last and am sure you'll appreciate coming here. The javax.imageio package provides a custom decoder (what I thought the CharsetDecoder class would do for me!) through the ImageIO class.

This here is the code. Before Coding, have you played some high performance games lately?





package examples;

import javax.imageio.*;
import java.awt.image.*;
import java.io.*;

public class Byter {

BufferedImage buffer;
File f;

protected void doThis(){
try{
//grab the file in a file reference, handle exception also
f = new File("amelipassport.jpg");
//use a static method read of ImageIO to buffer file
buffer = ImageIO.read(f);
//test buffer. You'll get two results, the ColorModel and Raster
//try and see
System.out.println(buffer.toString());
}
catch(IOException e){
e.printStackTrace();
System.err.println("File not found");
}
finally{
//finally call the raster for character rep.
//of the pixels in each cell. int returned by getRGB is 8 bits
for (int i=0; i<314;i++){
for(int j=0; j<274; j++){
System.out.print(buffer.getRGB(j,i)+",");
}
System.out.println();
}
}
}

public static void main(String[] args){
Byter by = new Byter();
by.doThis();
}

}

little challenge: send the output of Sysout to a “.txt” file and you'll see the table arrangement of the character representation of the colors you saw in the picture above.

A picture doesn't say a thousand words, you'll never understand them unless you know the language it was speaking in.

When the code ran, what I read from the output was that the picture has two components, a ColorModel and a Raster of image data. The results i got for the young beautiful dark african in the picture above is: This image is one of 8 bits in RGB colors, in windows style BGR color model with Red, Green and Blue of 3 bytes. There is no alpha value in the picture because this is false. The picture is set to 100% transparency and has a width of 274 pixels with a height of 314 pixels.
Try your hands on any picture of your choice and try reading what was said.

But for sure, appreciate colors, appreciate beauty and appreciate the picture even if the language seems difficult for you to understand.



No comments: