|
@ -2,11 +2,18 @@ package com.ekexiu.portal.util;
|
2
|
2
|
|
3
|
3
|
import java.awt.image.BufferedImage;
|
4
|
4
|
import java.io.ByteArrayInputStream;
|
|
5
|
import java.io.ByteArrayOutputStream;
|
|
6
|
import java.io.File;
|
|
7
|
import java.io.IOException;
|
5
|
8
|
|
6
|
9
|
import javax.imageio.ImageIO;
|
7
|
10
|
|
|
11
|
import sun.misc.BASE64Encoder;
|
8
|
12
|
import sun.misc.BASE64Decoder;
|
9
|
13
|
|
|
14
|
/**
|
|
15
|
* 将base码解码成图片格式。
|
|
16
|
*/
|
10
|
17
|
@SuppressWarnings("restriction")
|
11
|
18
|
public class Base64 {
|
12
|
19
|
public static BufferedImage getBase64(String base64) {
|
|
@ -20,4 +27,18 @@ public class Base64 {
|
20
|
27
|
return null;
|
21
|
28
|
}
|
22
|
29
|
}
|
|
30
|
|
|
31
|
public static void main(String[] args) throws IOException {
|
|
32
|
BASE64Encoder encoder = new sun.misc.BASE64Encoder();
|
|
33
|
File f = new File("D:/application/Workspaces/ekexiu.com.portal/src/main/webapp/images/head/03BF8D4ABF19481AA7BE4CD9509E3243_l.jpg");
|
|
34
|
BufferedImage bi = ImageIO.read(f);
|
|
35
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
36
|
ImageIO.write(bi, "jpg", baos);
|
|
37
|
byte[] bytes = baos.toByteArray();
|
|
38
|
String base64 = encoder.encodeBuffer(bytes).trim();
|
|
39
|
BufferedImage bi1 = Base64.getBase64(base64);
|
|
40
|
File file = new File("D:/测试图片.jpg");//可以是jpg,png,gif格式
|
|
41
|
ImageIO.write(bi1, "jpg", file);//不管输出什么格式图片,此处不需改动
|
|
42
|
System.out.println("图片保存成功!");
|
|
43
|
}
|
23
|
44
|
}
|