Skip to content

Instantly share code, notes, and snippets.

@zevnull
Created May 7, 2013 08:03
Show Gist options
  • Save zevnull/5530989 to your computer and use it in GitHub Desktop.
Save zevnull/5530989 to your computer and use it in GitHub Desktop.
Parse image
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ParseImg extends Component
{
//public static String content = "";
public static void main( String[] foo )
{
System.out.println( "@@@@@@@@@@@@@@" );
new ParseImg();
}
public void printPixelARGB( int pixel )
{
int alpha = ( pixel >> 24 ) & 0xff;
int red = ( pixel >> 16 ) & 0xff;
int green = ( pixel >> 8 ) & 0xff;
int blue = ( pixel ) & 0xff;
System.out.println( "argb: " + alpha + ", " + red + ", " + green + ", " + blue );
}
private void marchThroughImage( BufferedImage image )
{
int w = image.getWidth();
int h = image.getHeight();
System.out.println( "width, height: " + w + ", " + h );
for( int i = 0; i < h; i++ )
{
for( int j = 0; j < w; j++ )
{
System.out.println( "x,y: " + j + ", " + i );
int pixel = image.getRGB( j, i );
printPixelARGB( pixel );
System.out.println( "" );
}
}
}
public ParseImg()
{
try
{
// get the BufferedImage, using the ImageIO class
// Image image = ImageIO.read(new File(file));
// BufferedImage buffered = (BufferedImage) image;
BufferedImage image = ImageIO.read( new File( "c:\\elementScreenshot.png" ) );
// BufferedImage image = ImageIO.read( this.getClass().getResource( "c:\\elementScreenshot.png" ) );
marchThroughImage( image );
}
catch( IOException e )
{
System.err.println( e.getMessage() );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment