The way the bit I tested works, I have an array of symbols in binary order, and each group of pixels is put into binary.
I can just post the code, if it helps:
public static String[] brl={
" ", "a", "1", "b", "\'", "k", "2", "l",
"`", "c", "i", "f", "/", "m", "s", "p",
"\"", "e", "3", "h", "9", "o", "6", "r",
"~", "d", "j", "g", ">", "n", "t", "q",
",", "*", "5", "<", "-", "u", "8", "v",
".", "%", "{", "$", "+", "x", "!", "&",
";", ":", "4", "|", "0", "z", "7", "(",
"_", "?", "w", "}", "#", "y", ")", "="
};
And the method that does the analysis:
public static String[] getText(BufferedImage processedImage) {
WritableRaster input=processedImage.copyData(null);
byte[][] bytes=new byte[processedImage.getWidth()/2][processedImage.getHeight()/3];
String[] ret=new String[processedImage.getHeight()/3];
float value;
for(int x=0; x<processedImage.getWidth(); x++) {
for(int y=0; y<processedImage.getHeight(); y++) {
value = input.getSample(x, y, 0);
System.out.print(", " + value);
int rx=x%2;
int ry=y%3;
// Is this bit set? If so, set it.
boolean isSet=(value>0);
// Get the bit offset.
int bit=(3*rx)+ry;
if((x/2<processedImage.getWidth()/2)&&(y/3<processedImage.getHeight()/3)) {
if(isSet) {
bytes[x/2][y/3]|=(1<<bit);
}
else {
bytes[x/2][y/3]&=~(1<<bit);
}
}// Range check.
}
System.out.print("\n");
}// Loops.
// Now, build the text.
for(int y=0; y<processedImage.getHeight()/3; y++) {
ret[y]="";
for(int x=0; x<processedImage.getWidth()/2; x++) {
ret[y] = ret[y] + brl[(int)(bytes[x][y])];
}}// Loop for byte scanning.
return ret;
}// Get Text.
看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
George... Don't do that.