import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; public class Test64Bit { public static void main(String[] args) { // System.out.println("-------->" + GetImageStr("e:/11.bmp")); // System.out.println("========>"+ GenerateImage(GetImageStr("e:/11.bmp"), "E:/cc.jpg")); String s = "我喜欢Java/\\\n"; System.out.println(s.length()); } // 将图片变成64位 public static String GetImageStr(String imgFilePath) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 byte[] data = null; // 读取图片字节数组 try { InputStream in = new FileInputStream(imgFilePath); data = new byte[in.available()]; in.read(data); in.close(); } catch (IOException e) { e.printStackTrace(); } // 对字节数组Base64编码 BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(data);// 返回Base64编码过的字节数组字符串 } // 将64位变成图片 public static boolean GenerateImage(String imgStr, String imgFilePath) {// 对字节数组字符串进行Base64解码并生成图片 if (imgStr == null) // 图像数据为空 return false; BASE64Decoder decoder = new BASE64Decoder(); try { // Base64解码 byte[] bytes = decoder.decodeBuffer(imgStr); for (int i = 0; i < bytes.length; ++i) { if (bytes[i] < 0) {// 调整异常数据 bytes[i] += 256; } } // 生成jpeg图片 OutputStream out = new FileOutputStream(imgFilePath); out.write(bytes); out.flush(); out.close(); return true; } catch (Exception e) { return false; } } }
![](https://static.zuidaima.com/resource/img/heart_ico.png)
DongYingdie LV2
2023年12月21日
1358849392 LV21
2023年11月18日
1314520xsw LV1
2021年12月7日
爱生活的阿文 LV1
2021年11月15日
无语问苍天 LV1
2021年7月30日
2469095052 LV8
2021年2月1日
dongzhan LV12
2020年12月8日
kk3215 LV2
2020年12月4日
chenhuahao LV18
2020年5月11日
一字清华 LV8
2020年4月4日
![](https://static.zuidaima.com/resource/img/cattle_ico.png)
DongYingdie LV2
2023年12月21日
1358849392 LV21
2023年11月9日
crosa_Don LV18
2022年4月1日
wlfzuidaima LV1
2022年3月30日
1314520xsw LV1
2021年12月7日
爱生活的阿文 LV1
2021年11月15日
无语问苍天 LV1
2021年7月30日
卖菜老农 LV4
2021年7月29日
2469095052 LV8
2021年2月1日
dongzhan LV12
2020年12月8日