Created
June 4, 2012 22:17
-
-
Save kartben/2871147 to your computer and use it in GitHub Desktop.
Convert BMP to 12-bit RGB values
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
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import javax.imageio.ImageIO; | |
public class Main { | |
/** | |
* @param args | |
* @throws IOException | |
*/ | |
public static void main(String[] args) throws IOException { | |
File f = new File("/Users/kartben/Downloads/gas.bmp"); | |
BufferedImage image = ImageIO.read(f); | |
int i = 0; | |
short convertedPixel = 0; | |
for (int x = 0; x < image.getWidth(); x++) { | |
for (int y = 0; y < image.getHeight(); y++) { | |
int pixel = image.getRGB(x, y); | |
byte red = (byte) (((pixel >> 16) & 0xff) / 16); | |
byte green = (byte) (((pixel >> 8) & 0xff) / 16); | |
byte blue = (byte) (((pixel) & 0xff) / 16); | |
convertedPixel = (short) (red * 256 + green * 16 + blue); | |
System.out.printf("0x%02X, ", convertedPixel); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment