Here you can find the source of rotate(byte[] bytes)
public static byte[] rotate(byte[] bytes) throws IOException
//package com.java2s; //License from project: Open Source License import javax.imageio.ImageIO; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.*; public class Main { public static byte[] rotate(byte[] bytes) throws IOException { ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BufferedImage src = ImageIO.read(inputStream); int height = src.getHeight(); AffineTransform transform = AffineTransform.getRotateInstance(Math.toRadians(90), height / 2, height / 2); AffineTransformOp transformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC); BufferedImage dst = new BufferedImage(src.getHeight(), src.getWidth(), src.getType()); transformOp.filter(src, dst);/*ww w . j a v a2s . co m*/ BufferedOutputStream stream = new BufferedOutputStream(outputStream); dst.flush(); ImageIO.write(dst, "JPEG", outputStream); stream.flush(); stream.close(); return outputStream.toByteArray(); } public static void write(byte[] bytes, String pathname) throws IOException { ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); FileOutputStream outputStream = new FileOutputStream(pathname); BufferedImage image = ImageIO.read(inputStream); ImageIO.write(image, "JPEG", outputStream); outputStream.flush(); outputStream.close(); } }