两种构建位图的方式

来源:互联网 发布:无人机传感器数据测试 编辑:程序博客网 时间:2024/06/07 14:06
handler.obtainMessage=Message msg;//这种方式获取消息对象节省资源msg.obj=bm;//obj 封转消息内容msg.what=1;//what  封装消息类型(成功|失败);handle.sendMessage(msg)//发消息final File file = new File(getCacheDir(), getNameFromUrl(spec));//第一个参数文件存放路径,第二个是文件名//接下来就要定义文件输出流了if(conn.getResponseCode() == 200){//6.拿到服务器返回的流InputStream is = conn.getInputStream();//从流中读取图片的数据,然后把数据保存到本地byte[] b = new byte[1024];int len;FileOutputStream fos = new FileOutputStream(file);while((len = is.read(b)) != -1){fos.write(b, 0, len);}fos.close();//通过本地路径构造一张位图对象Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath())//从流中读取一张位图Bitmap bm=BitmapFactory.decodeStream(is)conn.setDoOutput(true);//必须设置这个给服务器的输出流才可用,文件上传
0 0
原创粉丝点击