Created
September 23, 2014 17:30
-
-
Save pbloem/a15acc128da3d085f3d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Color; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import javax.imageio.ImageIO; | |
/** | |
* Simple demonstration of the bare necessities required to crate an image file | |
* @author Peter | |
*/ | |
public class MakeImage | |
{ | |
/** | |
* @param args | |
* @throws IOException | |
*/ | |
public static void main(String[] args) throws IOException | |
{ | |
int width = 600; | |
int height = 400; | |
// Create the image | |
BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); | |
// Loop over all pixels | |
for (int i = 0; i < width; i++) | |
for (int j = 0; j < height; j++) | |
// set to a given color | |
im.setRGB(i, j, new Color(0.1f, 0.2f, 0.4f).getRGB()); | |
// Write the image to the file system | |
ImageIO.write(im, "PNG", new File("myimage.png")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment