Android InputStream转Bitmap
2016-03-11 15:32
591 查看
android socket服务端 接收Delphi socket客户端发来的图片,保存到bitmap中,代码如下:
public static Bitmap readInputStreamToBitmap(InputStream ins, int fileSize) { if (ins == null) { return null; } byte[] b; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { byte[] buffer = new byte[1024]; int size = -1; int len = 0;// 已经接收长度 size = ins.read(buffer); while (size != -1) { len = len + size;// bos.write(buffer, 0, size); if (fileSize == len) {// 接收完毕 break; } size = ins.read(buffer); } b = bos.toByteArray(); bos.close(); } catch (IOException e) { e.printStackTrace(); return null; } if (b.length != 0) { return BitmapFactory.decodeByteArray(b, 0, b.length); } return null; }
相关文章推荐
- [Android]AndFix使用说明
- Android Volley 基本用法及解析
- Android WebView与JavaScript交互(一)
- Android WebView+JSON+JavaScript
- 【Music】音乐切换封面没有变化
- Android中JNI程序的编写
- Android xUtils框架(一) DbUtils
- Android 7.0 给开发者带来了什么
- android 对象序列化
- ubuntu14.04Tls 64位完美搭建android开发环境。
- Android环境搭建
- Android 控件重复初始化影响隐藏和显示的控制
- Gradle, Android and the ANDROID_HOME SDK location
- Android PullToRefreshLayout下拉刷新控件的终结者
- android开机动画bootanimation
- Android之Glide获取图片Path、Bitmap用法
- Android开发从系统图库中选择一张图片的方法
- Android属性动画封装,快速构建动画
- Android PDF开发:android-pdfview
- [Android Studio] Android Studio常用快捷键