Java中如何把图片转换成二进制流?
使用java的IO流对图片进行二进制读取操作即可
示例为:读取图片为二进制流,并写入到其他图片中
static void testCopyImage(){ File source=new File("E:\\share\\Wallpaper\\Bliss.jpg"); File desk=new File("d:\\images"); if(!desk.exists()){ desk.mkdir(); } try { FileInputStream inputStream=new FileInputStream(source); FileOutputStream outputStream=new FileOutputStream(new File("d:/images/Bliss.jpg")); int ch=inputStream.read(); while(ch!=-1){ outputStream.write(ch); ch=inputStream.read(); } inputStream.close(); outputStream.close(); System.out.println("图片复制成功!"); } catch (FileNotFoundException e) { System.out.println("文件不存在:"+e.getMessage()); } catch (IOException e) { System.out.println("文件读取错误:"+e.getMessage()); } }