从网络下载图片然后本地获取是黑色的---(解决方法)
工具/原料
方法/步骤
11、检查当前应用主题颜色如图:如果是这种形式,表示app所有默认设置主题为黑色无titleBar,这时候就要注意了
2(这里测试图片是从网络获取的需要保存到本地然后)代码如下:(在某个地方调用执行并将数据保存到本地sd卡所创建的目录,然后每次获取图片都从本地获取)注意标红的地方,因为png默认的效果是最好的,而其他的图片在android系统中可能会出现失真的情况这个步骤处理过之后小图片也就是缩略图正常情况下也就显示正常了。 protected class downAndSaveImage implements Runnable { // TODO 异步保存图片 List urlStrArray, imgNameArray; URLConnection conn = null; String filePath; int where; public downAndSaveImage(List urlStrArray, List imgNameArray, String filePath, int where) { this.urlStrArray = urlStrArray; this.imgNameArray = imgNameArray; this.filePath = filePath; this.where = where; } public void run() { try { isClearFile(new File(filePath)); for (int i = 0; i < urlStrArray.size(); i++) { try { // Log.e('cccc' + urlStrArray.size(), // urlStrArray.get(i)); // Log.e('bbbb' + imgNameArray.size(), // imgNameArray.get(i)); File imageFile = new File(filePath, imgNameArray.get(i)); // 图片已下载 if (imageFile.exists()) continue; Bitmap itemBitmap = null; URL url = new URL(urlStrArray.get(i)); InputStream in = url.openStream(); itemBitmap = BitmapFactory.decodeStream(in); MyVariables.UmengVariables.FLOW_DOWNLOAD += itemBitmap .getHeight() * itemBitmap.getWidth(); try { imageFile.createNewFile(); FileOutputStream fos = new FileOutputStream( imageFile); itemBitmap.compress(CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { continue; } } urlStrArray = null; imgNameArray = null; } catch (Exception e) { e.printStackTrace(); } if (where == 0) { Message msg = new Message(); msg.getData().putInt('index', 0); handler.sendMessage(msg); } else if (where == 1) { Message message = new Message(); message.getData().putInt('type', 11); // 向目标handler发送消息 handler_showtopic.sendMessage(message); } else if (where == 2) { Message message = new Message(); message.getData().putInt('type', 15); // 向目标handler发送消息 handler_showtopic.sendMessage(message); } } }
3如果需要点击小图查看大图片的情况下,有可能会出现如下图的情况:
注意事项