rna2117
最近评论
文章分类
    收藏
      相册
      存档
      软件项目交易
      订阅我的博客
      XML聚合  FeedSky
      订阅到鲜果
      订阅到Google
      订阅到抓虾
      订阅到BlogLines
      订阅到Yahoo
      订阅到GouGou
      订阅到飞鸽
      订阅到Rojo
      订阅到newsgator
      订阅到netvibes

      原创 ISAPI 返回浏览器图片格式 我的第一个技术BLOG收藏

       | 

       终于解决了,ISAPI在返回时是一个图片而不是一个网页的问题了,为了这个东西我试验了ATL SERVER也不好用,挺郁闷的。但是还好,最后 在CSDN 上若要以除 HTML 之外的其他格式发送回来自 ISAPI 服务器的数据

      GIF 格式,该格式是二进制格式。若要发送回二进制数据,例如将 GIF 格式图像作为输出,将需要完成某些替换步骤。因为 CHtmlStream 类不允许单独的字节流,所以需要创建从 CHtmlStream 派生的类,然后使用该类将输出发送到客户端。下面是示例类:

      class CBinaryHtmlStream : public CHtmlStream
      {
      public:
         // we have a special overload of << to allow for a single byte
         CBinaryHtmlStream& operator<<(BYTE b)
         {
            Write(&b, 1);
            return *this;
         }
      }

      若要使用此流发送数据,请用以下主干代码代替 OutputXBM 函数:

      static const TCHAR szContentType[] = _T("Content-Type: image/gif\r\n");
      
      void CCounterExtension::OutputXBM(CHttpServerContext* pCtxt, CString& szDigits)
      {
         // some code here which takes szDigits and creates a new image
         // which has the GIF representation of those digits. This
         // image will be stored in memory at m_ImageByteArray[].
         // The number of bytes in the image is stored in m_nNumberBytes.
      
         // Start by writing the proper content type to the client
         AddHeader(pCtxt, szContentType);
      
         CString strLength;
         strLength.Format("Content-Length: %d\r\n", m_nNumberBytes);
         AddHeader(pCtxt, (LPCTSTR)strLength);
      
         CBinaryHtmlStream* pStream = new CBinaryHtmlStream;
         ISAPIVERIFY(pStream != NULL);
      
         int nCount;
         for (nCount = 0; nCount<m_nNumberBytes; nCount++)
            *pStream << m_ImageByteArray[nCount];
      
         *pCtxt << *pStream;
      
         delete pStream;
      
         // ... more code here ...
      }

      最终我对程序加以改造实现了,希望以后和大家多多交流,CSDN上说的没有错,但是还是需要在改进一下 m_ImageByteArray[nCount]

      目前我是把图片从本地磁盘上读出来,然后

      用一个BYTE *pa= new BYTE[NN]存储;然后代替才达到输出成功的效果,多多指教!

      发表于 @ 2008年03月18日 14:44:00|评论(loading...)|编辑

       | 

      评论:没有评论。

      发表评论  


      当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
      Csdn Blog version 3.1a
      Copyright © rna2117