Random Color Image
A very simple java-based utility that generates a PNG image of a random color. This was mainly created as an example on how to generate and return a binary image back to fech space.
Returns: An Image (PNG)
Calling Method(s):
Coded in: Java
Utility Code:
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class RandomImageGenerator
{
public static void main(String[] args) throws IOException
{
//Simple, small image resolution. It can be even smaller, honestly.
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
//Start a graphics engine for the image and fill in data with a random color (three random int values).
//because I am incredibly considerate of memory. Fight me.
Graphics2D g2d = image.createGraphics();
g2d.setColor(new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256)));
g2d.fillRect(0,0,100,100);
g2d.dispose();
//Format the image to PNG format and write it straight to console output, which will return to fech space.
ImageIO.write(image, "png", System.out);
//Flush the output because that is always a good practice.
System.out.flush();
}
}
Give Feedback
Community's Feedback on Utility
Utility Credits and Resources
(no credits mentioned for this utility)