图片转换

2018-05-15  本文已影响12人  Mylovesunshine

将图片转换成二进制字节流

public class PhotoTest{

  public static void main(String[] args) throws IOException{

/*

*将图片转换成二进制字节流

*/

byte[] imageByte;

File file1 = new File("D:/w.jpg");//需要转换成二进制字节流的文件的绝对路径

FileInputStream fls = new FileInputStream(file1);

imageByte = new Byte[ (int) file1.length() ];

fls.read(imageByte);

fls.close();

/*

*将二进制字节流转换成图片

*/

File file2 = new File("D:/p.jpg");//发现不管是jpg还是jpeg或者是png甚至是gif都能将图片显示出来....

FileOutputStream fos = new FileOutputStream(file2);

fos.write(imageByte);

fos.close();

  }

}

可以看到上面的代码可以运行了

上一篇 下一篇

猜你喜欢

热点阅读