/** * 从文件中拿图片 * * @return */ private static Bitmap getBitmapFromFile(Context con, String url, boolean blean) { String imageName = ""; if (!url.startsWith("http")) { imageName = url.substring(url.lastIndexOf("/") + 1); } else { imageName = Utils.getMD5Str(url); } if (url.contains("ba57b8e1463b63cb01463b7a18eb0083")) { MyLogger.commLog().e(imageName); } Bitmap bitmap = null; File file = null; String cacheDir = Utils.getCacheDir(con, "picture"); if (imageName != null) { try { file = new File(cacheDir, imageName); if (file.exists()) { // DisplayMetrics dm = context.getResources().getDisplayMetrics(); // int hh = dm.heightPixels;// 这里设置高度为800f // int ww = dm.widthPixels;// 这里设置宽度为480f bitmap = decodeSampledBitmapFromFile(cacheDir + "/" + imageName, 100, 100); } } catch (Exception e) { e.printStackTrace(); bitmap = null; } } if (bitmap != null) { addBitmapToMemoryCache(url, bitmap); MyLogger.commLog().d(url); } return bitmap; }
@Override protected Bitmap doInBackground(String... params) { Bitmap data = null; if (url != null) { try { URL c_url = new URL(url); String imageName = Utils.getMD5Str(url); setBitmapToFile(imageName, c_url.openStream()); } catch (FileNotFoundException exception) { MyLogger.commLog().w("~~~~~~文件不存在~~~~~~~~·" + (url == null ? "" : url)); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return data; }