BASE64转图片 工具类
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) { // 测试从Base64编码转换为图片文件 String strImg = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7UAAALKCAMAAADahIanAAAAAXNSR0IArs4c6QAAAORQTFRF////MjIy+zg49/r74/H/qampSsPoIp//6e/zzc3N/34At+7/0v//6///Mo3T040y/9ONMjKNjtP////rs2wyMmyz67Ns///TMjJsIrL/p+r/izIybDIybLPqrav//cLC5+7r/+uz+3d3/Z2diMf1+/Lz/9v/3d/iX6P/iDKEg9v/3eWz4fPT4siN/+3//9/fYcb/68j/06ptSuP6ZKnr+1dXg5//u8XndGqzz7f/tnNtMofT0/H/vYcyn2mNZIfTTl1emmwyUIGIwcHBazKJlXVwoqWRhbGzZDIys40ys9Ozy/r3aYRMtgAAIABJREFUeNrtnQlbG0e2QKuxa5g8rQhJYC2AsLAdMDFg43iJEy9xPDP//we92rq7qrpZhNlKnBNba0uQ+93Dvbe6jISA8/hl6f43Vs+iJ3r5zRfiaHUkREO0XpxxsPd+j+FcVrEIa2/L2tUnDSFGq4tau/Nlbm+8fPeHuvw0L586ybLBHwd/jw7+k2nWGodv7BOHH8P30AesNdRL9Zu9HJujs81R/rR9mflCB3+pg+eHWUH+jm8O1xr25qc3xVfP3NfFWqxdAmsbwcHO2tXVo8elyJex1rNn7qw9+LtRGGPdfPnr6PGntX+MhM7pirV/Pd75U1n7cjzP7X+88z2y9sPo5a8N5ffgD/dT4lfPRnWIftPCVPXVTt6YN9bvjLVYuwTWzns+uu4+cfV3oVqb106li7HWSTP442Tup7GrnqrmvXyXi/4xtPZkrqydGg+9WntS/lT4+Mlcag3138La/Gj7nvnX1cpjLdYuYYe8EGfPtSeufzWeqfZUq3zimWT8Un88e6q11lg79zptr9a+HBc/HA5//GV+Vmhjg1rrTA6spUPGWqytsfaw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tXaVnWuVce/D+R3a8h64m2pLttMzOYHwGjrSFBrIbVaq1Qy423YIYuOqqJdbzVKtcVt7afyUVk7nBprX479NSZtc32HbJye9IKvna//bD0pG2OrUC7SGdaaklhYG7bR6kA91z57cuxO5NgG2omuHnz/pFiJbm611NfNX/6euRbSmWs/Z9+fV6ztZp//bmgNfWunytr1ftvMuvN8rlWCukNs9xvWWuHO1071pX7Ae78te7rWrEa9PRLP9NW+vTzX2vf7vrVbQVv71lqrqqx7hX26KM+mprvzuatHwq412yMes4YMqVirtH1esbZvt0t0pm7ThLAibvx6mHkD6uzdyVR10u2u2TqxMZ4KUb+G7Ppkc7vb9haW9AalraMtu8y7ZZaOtsoTM561lVM9ubX+6pUt2dra49W50fbYOfk+L89vzc+JffPUyP3AsKeVOF8LiVj77dvznHxv1GySb0E0MnqrTO3idJB+UJ/1yX6MzYla9aKpGnBF1Vp9QleZ3RZuI2TQJJv5MiqWPvW19thVz5aRPWxrj/W53+aW+SHw9snxql2eznc3qpeY8uqa52er+erxk+I0FNbCvbd2x9uHvHPr35EeLffPsfYWMWeEsBZSsPbRv4t9yDuP7uj7uhfW3miUAcgnogzkExBlIJ+IMgD5RJSBfAKiDOQTEOXr4REUrBACopwC4t9QsEIIiHIKYC35RJSxlnwCooy15BNRhoWttf/khXwCopyKtTv5v1TbMXflL+bqn3/IJyDK99TaQlqn7fPvzz//Y/856fd///uXrzvqT3Gw7/Lzz8/JJyDK18//A6RuuUT9/FEuAAAAAElFTkSuQmCC"; String imgtype=""; String imgAddress=""; String str1 = strImg.split(",")[0]; imgAddress=strImg.split(",")[1]; String str1_1 = str1.split(";")[0]; String imgType = str1_1.split("/")[1]; System.out.println(imgType); GenerateImage(imgAddress, "D:\\wangyc1."+imgType); // 测试从图片文件转换为Base64编码 System.out.println(GetImageStr("d:\\wangyc.jpg")); } 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编码过的字节数组字符串 } 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; } } }