(400, 400, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, 400, 400);
g2d.setColor(Color.red);
g2d.drawRect(100, 50, 100, 50);
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
PNGTranscoder t = new PNGTranscoder();
TranscoderOutput output = new TranscoderOutput(ostream);
t.writeImage(img, output);
return ostream.toByteArray();