这个是最简单的图片转化为二进制,再将二进制转化为图片
public static void main(String[] args) {
//图片转化为二进制
byte[] imageBytes = null;
try (FileInputStream fileInputStream = new FileInputStream(new File("C:/4.jpg"));) {
imageBytes = new byte[fileInputStream.available()];
fileInputStream.read(imageBytes);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(imageBytes);
//二进制转化为图片
try (FileOutputStream fileOutputStream = new FileOutputStream(new File("C:/Users/2.jpg"));) {
fileOutputStream.write(imageBytes);
} catch (IOException e) {
e.printStackTrace();
}
}