网络图片地址转为字节流
来源:互联网 发布:机器人用什么编程 编辑:程序博客网 时间:2024/06/05 15:44
public class GetByteByNetUrl { /** * 根据地址获得数据的字节流 * @param strUrl 网络连接地址 * @return */ public static byte[] getImageFromNetByUrl(String strUrl){ try { URL url = new URL(strUrl); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5 * 1000); InputStream inStream = conn.getInputStream();//通过输入流获取图片数据 byte[] btImg = readInputStream(inStream);//得到图片的二进制数据 return btImg; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 从输入流中获取数据 * @param inStream 输入流 * @return * @throws Exception */ public static byte[] readInputStream(InputStream inStream) throws Exception{ ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while( (len=inStream.read(buffer)) != -1 ){ outStream.write(buffer, 0, len); } inStream.close(); return outStream.toByteArray(); }
0 0
- 网络图片地址转为字节流
- 根据网络图片地址获取资源的字节流
- Android将图片转为字节流存储在SharedPreferences
- 图片转为Byte字节数组 字节数组生成图片
- 将本地图片转为base64字节
- 网络图片url转为bitmap
- 获取网络图片并转为base64编码
- 网络字节序和地址转换
- ip地址 网络字节序 主机字节序的关系
- 本地文件转为图片流返回
- 本地文件转为图片流返回
- 查看网络图片的地址
- Linux 网络编程——网络字节序、地址转换
- Linux 网络编程——网络字节序、地址转换
- 【linux网络编程】网络字节序、地址转换
- Linux 网络编程——网络字节序、地址转换
- 读淘宝页面字节流提取宝贝图片地址宝贝标题宝贝价格
- 网络字节流和主机字节流
- 【CSS3】创意页面切换效果集合
- 小猪用Git一年多后的总结精华
- 疯狂ajaxj讲义摘录
- Java日志之log4j
- JAVA知识点(整理学习中。。)
- 网络图片地址转为字节流
- Oracle Data Integrator 12c----包(Package)
- 如何在myeclipse中导入能让配置文件有自动补全功能的dtd文件
- Javascript实用的语句
- 关于android studio 出现Error:Execution failed for task ':app:buildInfoDebugLoader'.的解决办法
- Oracle Data Integrator 12c-----场景(Scenario)和调度(Schedule)
- 设计模式整理
- 🈲Eclipse通过jdbc连接数据库制作简单登陆界面【新手必看】
- java中map集合的几种迭代方式