截取图片网址,将 图片显示到RichTextBox 中

来源:互联网 发布:linux管理员招聘 编辑:程序博客网 时间:2024/06/05 10:25

//文本内容

string content="<img height='164' width='192' src='http://devel.zongzk.com/upload/uuimp_ft/6769/9aa3cc281f2ad5f5534ad36a97e715fe.tmp'>sdfsadfa<img height='164' width='192' src='http://devel.zongzk.com/upload/uuimp_ft/6769/9aa3cc281f2ad5f5534ad36a97e715fe.tmp'>123123";


                   if (content.Contains("<img"))

                    {
                        while (content.Trim().LastIndexOf("<img") >= 0)
                        {
                            string StrImg = string.Empty;
                            int ImgStartIndex = content.IndexOf("<img");
                            string sssss = content.Substring(0, ImgStartIndex);
                            this.richTextBox1.AppendText(sssss);
                            int ImgEndIndex = content.IndexOf("'>", ImgStartIndex);
                            StrImg = content.Substring(ImgStartIndex, ImgEndIndex - ImgStartIndex + 2);

                            int ImgUrlStartIndex = StrImg.IndexOf("src='");
                            int ImgUrlEndIndex = StrImg.IndexOf("'>");
                            string ImgUrl = StrImg.Substring(ImgUrlStartIndex + 5, ImgUrlEndIndex - ImgUrlStartIndex - 5);

                            image = InterfaceURL.getAvatarByURL(ImgUrl);
                            Clipboard.SetDataObject(image, false);
                            richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Bitmap));

                            Clipboard.Clear();
                            content = content.Substring(ImgEndIndex + 2, content.Length - ImgEndIndex - 2);
                        }
                    }
                    this.richTextBox1.AppendText(content + "\n");
原创粉丝点击