从数据库中读出RTF格式的数据利用http://topic.csdn.net/u/20081223/16/410d78ec-2d99-42b4-be7d-a38911240d05.html贴中所示方法(以下代码有修改)string _RtfText=rtf;//rtf为数据库中读出RTF类型数据
            IList<string> _ImageList =new List<string>();
            while(true)
            {
                int _Index = _RtfText.IndexOf("pichgoal");
                if(_Index==-1)break;
                _RtfText=_RtfText.Remove(0,_Index+8);                _Index = _RtfText.IndexOf("\r\n");
                
                int _Temp = Convert.ToInt32(_RtfText.Substring(0, _Index));
                _RtfText = _RtfText.Remove(0, _Index);
                _RtfText = _RtfText.Replace("\r\n", "");                _Index = _RtfText.IndexOf("}");
                _ImageList.Add(_RtfText.Substring(0, _Index));                _RtfText = _RtfText.Remove(0, _Index);                
                
            }            for (int i = 0; i != _ImageList.Count; i++)
            {
                System.IO.FileStream _File = new FileStream(Server.MapPath("~/image/")  + i.ToString() + ".jpg", System.IO.FileMode.Create);
                int _Count=_ImageList[i].Length/2;                for (int z = 0; z != _Count; z++)
                {
                    string _TempText=_ImageList[i][z*2].ToString()+_ImageList[i][(z*2)+1].ToString();
                    _File.WriteByte(Convert.ToByte(_TempText, 16));
                }                _File.Close();
            }                       MessageBox.Show(_ImageList.Count.ToString());
这种方法得到的jpg图像文件在本机能被ACDSEE显示,在asp.net的设计模式下也能显示。但运行后在浏览器中却不能显示了,利用ACDSEE将其进行格式转化后的图像却不存在这个问题。请高手指点该如何解决啊!

解决方案 »

  1.   

    你看网站目录下是否生成了图片,images文件夹允许匿名访问
      

  2.   

    谢谢,但是我觉得好像不是这个问题。图片是肯定生成了的,网站还没发布,是在调试过程中就存在问题。我觉得是图片格式问题,因为用火狐浏览器直接打开图片时会显示“图像因其本身有错而无法显示”,应该是程序自动生成的图像编码不正确,图像查看程序如ACDSEE能自动纠错查看,而浏览器为了防注入式攻击而对图像格式要求高,所以看不了。
      

  3.   

    经过上网查找,已经找到以上问题的解决方法。                    //数据库读出的RTF字符串。
                        string _RtfText = tempStr;
                        IList<string> _ImageList = new List<string>();
                        while (true)
                        {
                            int _Index = _RtfText.IndexOf("pichgoal");
                            if (_Index == -1) break;
                            _RtfText = _RtfText.Remove(0, _Index + 8);                        _Index = _RtfText.IndexOf("\r\n");                     
                            _RtfText = _RtfText.Remove(0, _Index);
                         
                                                 _Index = _RtfText.IndexOf("}");
                            _ImageList.Add(_RtfText.Substring(0, _Index).Replace("\r\n", ""));                        _RtfText = _RtfText.Remove(0, _Index);                    }                 
                        Byte[] buffer;
                        buffer = null;
                        for (int i = 0; i != _ImageList.Count; i++)
                        {
                         //   System.IO.FileStream _File = new FileStream(Server.MapPath("~/image/") + i.ToString() + ".png", System.IO.FileMode.Create);
                            int _Count = _ImageList[i].Length / 2;
                             buffer = new Byte[_ImageList[i].Length/2];                        for (int z = 0; z != _Count; z++)
                            {
                                string _TempText = _ImageList[i][z * 2].ToString() + _ImageList[i][(z * 2) + 1].ToString();
                            //    _File.WriteByte(Convert.ToByte(_TempText, 16));
                                buffer[z] = Convert.ToByte(_TempText, 16);  
                            }                   //    _File.Close();
                        }
                        MemoryStream ms = new MemoryStream(buffer);
                        Image _a = Image.FromStream(ms);
                    _a.Save(Server.MapPath("~/image/") + i.ToString() + ".png");
                      //  Bitmap _a = new Bitmap(Application.StartupPath + "\\" + "0.dat");