Java Program To Convert Image To Byte Array And Vice Versa
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import java.nio.file.Files;
class ByteToImage{
public static void main (String[] a)throws IOException{
// Convert Image To Byte Array
File fi = new File("rainforest.jpg");
byte[] imageInBytes = Files.readAllBytes(fi.toPath());
//Convert Byte Array To Image
InputStream in = new ByteArrayInputStream(imageInBytes);
BufferedImage b = ImageIO.read(in);
ImageIO.write(b, "jpg", new File("rainforest1.jpg"));
}
}
No comments:
Post a Comment