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

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

代码如下

 String[] strs = body.split(" ");
							for(int i = 0; i < strs.length; i++){
								//表情
								if(strs[i].contains(":") || strs[i].contains("(") || strs[i].contains(")") ){
									try{
									URL emoticon_url = emoticonManager.getEmoticonURL(emoticonManager.getEmoticon(strs[i]));
									String emoticon_path = emoticon_url.getPath();
									emoticon_path = "file:///C|/" + emoticon_path.substring(emoticon_path.indexOf(":/") + 2);
									strs[i] = "<img src='"+ emoticon_path + "'/>";
								}catch (Exception e) {
								}finally{
								}
								}
								//截图
								if(strs[i].contains("Tmp://")){
									   String tmpPath = strs[i].substring(strs[i].indexOf("Tmp://") + 6, strs[i].indexOf("#"));
									   File rootPath =  new File(Spark.getSparkUserHome(), "/tempImages");
						                File f = new File(rootPath.getAbsolutePath(), tmpPath);
						                URL fileURL=null;
										try {
											fileURL = f.toURI().toURL();//本地URL  html可识别
										} catch (MalformedURLException e) {
											// TODO Auto-generated catch block
											e.printStackTrace();
										}
						                String file_path=fileURL.getPath();
						                file_path = "file:///C|/" + file_path.substring(file_path.indexOf(":/") + 2);
						                if(f.exists()){
						                	strs[i] = "<img src='"+ file_path + "'/>";
						                }else{
						                 	strs[i] = "<img src='"+ f.getAbsolutePath() + "'/>";
						                }
						                
								}
								if(strs[i].contains("&lt;img&gt;")){//自定义的标签<img>
									strs[i]= strs[i].substring(0,strs[i].indexOf("&lt;img&gt;"));
								}
								builder.append(strs[i]);
							}

 效果如图所示:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值