美文网首页
图片转换

图片转换

作者: Mylovesunshine | 来源:发表于2018-05-15 21:57 被阅读12次

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

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();

  }

}

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

相关文章

网友评论

      本文标题:图片转换

      本文链接:https://www.haomeiwen.com/subject/pitudftx.html