import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class CodeTest {
static private String hex(int value) {
String result = Integer.toString(value, 16);
if (result.length() < 2) {
result = "0" + result;
}
return result;
}
public static void main(String[] args) throws IOException, InterruptedException {
BufferedImage image = ImageIO.read(new File("/home/rli/test.png"));
for (int x = 0; x < image.getWidth(); x++) {
int pixel = image.getRGB(x, 0);
int red = (pixel & 0x00ff0000) >> 16;
int green = (pixel & 0x0000ff00) >> 8;
int blue = pixel & 0x000000ff;
System.out.println("#" + hex(red) + hex(green) + hex(blue));
}
}
}