Created
July 5, 2011 20:18
-
-
Save cfaulkingham/1065818 to your computer and use it in GitHub Desktop.
Used to convert an Jpeg image into values that my Drawbot can read.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Colin Faulkingham Drawbot Image Processing Code 2011 | |
* | |
*/ | |
import java.awt.*; | |
import java.awt.image.*; | |
import java.io.*; | |
import javax.imageio.*; | |
public class LoadImageApp extends Component { | |
public static void main(String[] args) { | |
try{ | |
BufferedImage img; | |
Writer output = null; | |
File file = new File("/blah.txt"); | |
output = new BufferedWriter(new FileWriter(file)); | |
img = ImageIO.read(new File( "/test1.jpg" )); | |
int w = img.getWidth(); | |
int h = img.getHeight(); | |
System.out.print("W:"+w+"xH:"+h); | |
for (int i=0; i<h; i++){ | |
for (int j=0; j<w; j++){ | |
int pixel = img.getRGB(j, i); | |
//int alpha = (pixel >> 24) & 0xff; | |
int red = (pixel >> 16) & 0xff; | |
int green = (pixel >> 8) & 0xff; | |
int blue = (pixel) & 0xff; | |
int med = (red+green+blue) / 3; | |
int out = med / 23; | |
//System.out.print(out); | |
String text = out+","; | |
output.write(text); | |
//System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue); | |
} | |
//System.out.println(); | |
output.write("\n"); | |
} | |
output.close(); | |
} | |
catch(IOException e){System.out.println(e);} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment