Delphi中自带的例子:
procedure TCustomerInfoModule.CustomerInfoModuleGetImageAction(
Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
var
Jpg: TJpegImage;
S: TMemoryStream;
B: TBitmap;
begin
Jpg := TJpegImage.Create;
try
B := TBitmap.Create;
try
B.Assign(BioLifeGraphic);
Jpg.Assign(B);
finally
B.Free;
end;
S := TMemoryStream.Create;
Jpg.SaveToStream(S);
S.Position := 0;
Response.ContentType := 'image/jpeg';
Response.ContentStream := S; // do not free the stream because the response
// object will handle that task.
finally
Jpg.Free;
end;
end;