记录几个有关image处理的API
2016-02-17 10:39
363 查看
1 将字节数组转换成BufferedImage对象
2 将BufferedImage对象转换成字节数组
3 通过BufferedImage设置图片大小
4 将字符串转换为base64数组
public static BufferedImage byte2BufferedImage(byte[] imageByte) throws Exception{ ByteArrayInputStream in = new ByteArrayInputStream(imageByte); BufferedImage image = ImageIO.read(in); return image; }
2 将BufferedImage对象转换成字节数组
public static byte[] bufferedImage2Byte(BufferedImage bufferImage) throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); boolean flag = ImageIO.write(bufferImage, "png", out); byte[] b = out.toByteArray(); return b; }
3 通过BufferedImage设置图片大小
public static BufferedImage zoomOutImage(BufferedImage originalImage, int width, int height){ BufferedImage newImage = new BufferedImage(width, height, originalImage.getType()); Graphics g = newImage.getGraphics(); g.drawImage(originalImage, 0, 0, width, height, null); g.dispose(); return newImage; }
4 将字符串转换为base64数组
public static byte[] getBase64Bytes(String image){ BASE64Decoder decoder = new BASE64Decoder(); try{ byte[] decodedBytes = decoder.decodeBuffer(image); return decodedBytes; }catch(Exception e){ e.printStackTrace(); } return null; }
相关文章推荐
- C#构建多线程应用程序(4) —— 并发问题
- 外层包含div
- Oracle 创建序列
- 钓鱼网站钓取大量QQ帐号密码被泄露钓鱼受害者每天过万(某先前被腾讯忽略的报告)
- Linux备份war包简单脚本
- 201602171037_《Js地理位置(摘)》
- (笔记)电路设计(十)之脉冲电路的应用
- noip1999导弹拦截c++语言
- 正则表达式
- 我回来了!
- c3p0连接池原理分析
- 在WPF上实现系统消息获
- spring+Quartz集群
- android是根据什么去选择drawable文件夹下的三种图片(png,jpg,gif)?图片导入
- android蓝牙开发入门到精通3---服务端客户端通信
- Android属性动画实战教程中篇
- Jvm工作原理学习笔记
- iOS: 常用的宏
- 从此落地生根
- 用线型布局的瀑布流实现增删系统相册的图片