基本信息
源码名称:解析网络图片
源码大小:2.31KB
文件格式:.txt
开发语言:Java
更新时间:2013-05-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
/** * * 解析网络图片. */ private Bitmap decodeBitmapFromNet(final String imagePath) { Bitmap bitmap = null; InputStream is = null; try { //HttpURLConnection conn = (HttpURLConnection) (new URL(imagePath)).openConnection(); //conn.setDoInput(true); //conn.connect(); //is = conn.getInputStream(); is = new URL(imagePath).openStream(); if (is == null) { decodeBitmapFailed(R.string.picture_decode_failed); return null; } BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true; options.inInputShareable = true; options.inJustDecodeBounds = true; if (!imagePath.substring(imagePath.lastIndexOf(".") 1) .equalsIgnoreCase(Constants.MPO)) // options.forceNoHWDoecode = true; // 获取原始分辨率 Log.i(TAG, "************" is.markSupported()); BitmapFactory.decodeStream(is, null, options); Log.d(TAG, "from dlna, options " options.outHeight " " options.outWidth); // 检测图片分辨率. if (isLargerThanLimit(options)) { closeSilently(is); mCanResponse = true; return setDefaultPhoto(); } is = new URL(imagePath).openStream(); //is = conn.getInputStream(); if (is == null) { decodeBitmapFailed(R.string.picture_decode_failed); return null; } // TODO 此处需要做优化,做动态缩放,暂时用固定的缩放比来缩放图片. //options.inSampleSize = 4; options.inSampleSize = computeSampleSizeLarger(options.outWidth, options.outHeight); options.inJustDecodeBounds = false; // options.forceNoHWDoecode = false; Log.d(TAG, "is : " is); bitmap = BitmapFactory.decodeStream(is, null, options); if (bitmap == null) { Log.d(TAG, "BitmapFactory.decodeStream return null"); decodeBitmapFailed(R.string.picture_decode_failed); } closeSilently(is); mCanResponse = true; return bitmap; } catch (MalformedURLException e) { Log.e(TAG, "MalformedURLException in decodeBitmap"); e.printStackTrace(); } catch (IOException e) { Log.e(TAG, "IOException in decodeBitmap"); e.printStackTrace(); } finally { closeSilently(is); } decodeBitmapFailed(R.string.picture_decode_failed); return null; }