// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Image2byte {
    public static void main(String[] args) throws IOException {
        BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
        Graphics g = bi.getGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, 100, 100);
        g.setColor(Color.BLUE);
        g.fillOval(20, 20, 60, 60);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(bi, "gif", baos);
        baos.close();
        byte[] b = baos.toByteArray();
        for(int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }
    }
}
