我用isapi作过一个,你用asp做com对象时,在html中加入<image src=pic.asp>
在pic.asp中调用com对象的方法来生成图象,把下面的例子该该应该没什么大问题。
//---------------------------------------------------------------------------
#include "Unit1.h"
#include "jpeg.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TWebModule1 *WebModule1;
//---------------------------------------------------------------------------
__fastcall TWebModule1::TWebModule1(TComponent* Owner)
: TWebModule(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TWebModule1::WebModule1WebActionItem1Action(
TObject *Sender, TWebRequest *Request, TWebResponse *Response,
bool &Handled)
{
tmp=Request->QueryFields;
width=StrToInt(tmp->Values["width"]);
height=StrToInt(tmp->Values["height"]);
Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
TJPEGImage *jpg= new TJPEGImage();
TMemoryStream *stream = new TMemoryStream();
try
{
pBitmap->Width=width;
pBitmap->Height=height;
pBitmap->Canvas->Brush->Color=clRed;
//pBitmap->Canvas->Brush->Style = bsDiagCross;
pBitmap->Canvas->Ellipse( 0,0,width,height);
jpg->Assign(pBitmap);
jpg->SaveToStream(stream);
stream->Position=0;
Response->ContentType = "image/JPEG";
Response->ContentStream = stream;
}
__finally
{
//delete stream; 内存流不能被删除,否则会出错(大概是因为流在返回时是
//持续的而不是间断的
delete pBitmap;
delete jpg;
}
}
//---------------------------------------------------------------------------