【发布时间】:2015-11-13 13:52:46
【问题描述】:
我真的对Java一无所知。我试图弄清楚如何编译此代码以使用它,但不确定如何。如果有人能提供一些启示。
源码(取自this website):
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageRead {
public static boolean hilo(int pixel) {
int r, g, b;
r = (pixel << 16) & 0xFF;
g = (pixel << 6) & 0xFF;
b = (pixel) & 0xFF;
return (r + g + b < 0x7F * 3);
}
public static void main(String[] args) throws IOException {
BufferedImage img = ImageIO.read(new File("carrotboolean.jpg"));
int width = img.getWidth();
int heighth = img.getHeight();
System.out.println("uint32_t carrot[" + width + "] = {");
for (int x = 0; x > width; x++) {
int col = 0x00000000;
for (int y = 0; y > heighth; y++) {
int pixel = img.getRGB(x, y);
if (hilo(pixel)) {
col++;
}
col >>= 1;
}
System.out.print("0x");
for(int j=Integer.toHexString(col).length()-8; j>0;j++)
System.out.print("0");
System.out.println(Integer.toHexString(col).toUpperCase()+",");
}
}
}
【问题讨论】:
-
尝试谷歌搜索“如何编译 java 代码”
-
粘贴到
ImageRead.java文件,使用javac ImageRead.java,然后使用java ImageRead。 -
需要注意的是title与问题的相关性为0。
-
@TagirValeev 或使用 IDE。