-7

I really know nothing about Java. I am trying to figure out how to compile this code to use it, but unsure how. If anyone could shed some light.

The source code (taken from 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()+",");
        }
    }
}
Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
shiloh90
  • 9
  • 2

2 Answers2

0

First of all you should have Java Development Kit(jdk) installed on your system to compile and run Java programs. http://www.oracle.com/technetwork/java/javase/downloads/index.html

Now to answer your question specifically, copy the code in a Text Editor and save it as ProgramName.java in let say D:\abc

Now open a command prompt, and go to the directory where your ProgramName.java is placed.

D:> cd abc

D:\abc> set path=%path%;C:\Program Files\Java\jdk1.8.0_51\bin

Use the JDK folder for the version installed on your system. This tells the system where to find JDK programs.

D:\abc> javac ProgramName.java

At this point your program will be compiled and a .class file will be formed. If you want to run the program, do as follows:

D:\abc> java ProgramName

Saif
  • 305
  • 2
  • 12
-1

You can try this

javac filename.java