截图后保存到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("<img>")){//自定义的标签<img>
- strs[i]= strs[i].substring(0,strs[i].indexOf("<img>"));
- }
- builder.append(strs[i]);
- }
效果如图所示:

|