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]存储;然后代替才达到输出成功的效果,多多指教!

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值