// bi is a TYPE_BYTE_BINARY type BufferedImage
BufferedImage rbi = new BufferedImage(w, h, bi.getType());
Graphics2D g = rbi.createGraphics();
// The java api indicated that the setBackground method is for RGB color model
g.setBackground(Color.WHITE);
// after rotation the magrin is filled by black color.
g.rotate(Math.toRadians(angle), w / 2, h / 2);
g.drawImage(bi, null, 0, 0);
g.dispose(); |