分享

XMPP群聊截图后在历史消息中显示图片

 WindySky 2016-02-18

截图后保存到xml中是用图片的信息来进行保存的,只需要通过图片的路径在本地找到对应的图片,加载到历史消息显示面板中即可。

代码如下

Java代码  收藏代码
  1. String[] strs = body.split(" ");  
  2.                         for(int i = 0; i < strs.length; i++){  
  3.                             //表情  
  4.                             if(strs[i].contains(":") || strs[i].contains("(") || strs[i].contains(")") ){  
  5.                                 try{  
  6.                                 URL emoticon_url = emoticonManager.getEmoticonURL(emoticonManager.getEmoticon(strs[i]));  
  7.                                 String emoticon_path = emoticon_url.getPath();  
  8.                                 emoticon_path = "file:///C|/" + emoticon_path.substring(emoticon_path.indexOf(":/") + 2);  
  9.                                 strs[i] = "<img src='"+ emoticon_path + "'/>";  
  10.                             }catch (Exception e) {  
  11.                             }finally{  
  12.                             }  
  13.                             }  
  14.                             //截图  
  15.                             if(strs[i].contains("Tmp://")){  
  16.                                    String tmpPath = strs[i].substring(strs[i].indexOf("Tmp://") + 6, strs[i].indexOf("#"));  
  17.                                    File rootPath =  new File(Spark.getSparkUserHome(), "/tempImages");  
  18.                                     File f = new File(rootPath.getAbsolutePath(), tmpPath);  
  19.                                     URL fileURL=null;  
  20.                                     try {  
  21.                                         fileURL = f.toURI().toURL();//本地URL  html可识别  
  22.                                     } catch (MalformedURLException e) {  
  23.                                         // TODO Auto-generated catch block  
  24.                                         e.printStackTrace();  
  25.                                     }  
  26.                                     String file_path=fileURL.getPath();  
  27.                                     file_path = "file:///C|/" + file_path.substring(file_path.indexOf(":/") + 2);  
  28.                                     if(f.exists()){  
  29.                                         strs[i] = "<img src='"+ file_path + "'/>";  
  30.                                     }else{  
  31.                                         strs[i] = "<img src='"+ f.getAbsolutePath() + "'/>";  
  32.                                     }  
  33.                                       
  34.                             }  
  35.                             if(strs[i].contains("<img>")){//自定义的标签<img>  
  36.                                 strs[i]= strs[i].substring(0,strs[i].indexOf("<img>"));  
  37.                             }  
  38.                             builder.append(strs[i]);  
  39.                         }  

 效果如图所示:


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多