欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java實(shí)現(xiàn)圖片與二進(jìn)制的互相轉(zhuǎn)換

 更新時間:2018年03月31日 10:28:05   作者:我心永恒  
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)圖片與二進(jìn)制的互相轉(zhuǎn)換,將圖片轉(zhuǎn)二進(jìn)制再將二進(jìn)制轉(zhuǎn)成圖片,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Java將圖片轉(zhuǎn)二進(jìn)制再將二進(jìn)制轉(zhuǎn)成圖片,供大家參考,具體內(nèi)容如下

import java.awt.image.BufferedImage;  
import java.io.ByteArrayInputStream;  
import java.io.ByteArrayOutputStream;  
import java.io.File;  
import java.io.IOException;  
 
import javax.imageio.ImageIO;  
 
import sun.misc.BASE64Decoder;  
import sun.misc.BASE64Encoder;  
 
public class TestImageBinary {  
  static BASE64Encoder encoder = new sun.misc.BASE64Encoder();  
  static BASE64Decoder decoder = new sun.misc.BASE64Decoder();  
    
  public static void main(String[] args) {  
    System.out.println(getImageBinary());  
      
    base64StringToImage(getImageBinary());  
  }  
    
  static String getImageBinary(){  
    File f = new File("c://20090709442.jpg");     
    BufferedImage bi;  
    try {  
      bi = ImageIO.read(f);  
      ByteArrayOutputStream baos = new ByteArrayOutputStream();  
      ImageIO.write(bi, "jpg", baos);  
      byte[] bytes = baos.toByteArray();  
        
      return encoder.encodeBuffer(bytes).trim();  
    } catch (IOException e) {  
      e.printStackTrace();  
    }  
    return null;  
  }  
    
  static void base64StringToImage(String base64String){  
    try {  
      byte[] bytes1 = decoder.decodeBuffer(base64String);  
        
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);  
      BufferedImage bi1 =ImageIO.read(bais);  
      File w2 = new File("c://QQ.bmp");//可以是jpg,png,gif格式  
      ImageIO.write(bi1, "jpg", w2);//不管輸出什么格式圖片,此處不需改動  
    } catch (IOException e) {  
      e.printStackTrace();  
    }  
  }  
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論