M
mawei
Unregistered / Unconfirmed
GUEST, unregistred user!
返回报错CGI的头不对,应该怎么改???
program counter;
{$APPTYPE CONSOLE}
uses SysUtils,
Windows,
Graphics,
JPEG,
Classes;
var
BitmapImage: TBitmap;
JPEGImage: TJPEGImage;
NumWidth: Byte;
NumStr: String[10];
Rect: TRect;
MemStream: TMemoryStream;
HandleStr: THandleStream;
CountValue: LongInt;
begin
{ Create the bitmap for the counter }
BitmapImage := TBitmap.Create;
{ Load the Font attributes }
with BitmapImage.Canvas.Fontdo
begin
Name := 'Arial';
Height := 16;
{ Pixels }
Color := clRed;
end;
{ Set the background color }
with BitmapImage.Canvas.Brushdo
begin
Color := clBlack;
end;
NumWidth := 5;
CountValue :=6356;
{ Create the count as a string }
NumStr := IntToStr(CountValue);
if NumWidth > 0 then
while Length(NumStr) < NumWidthdo
NumStr := '0' + NumStr;
{----------------------------------------------------------------}
{----------------- Build the image -----------------------------}
{----------------------------------------------------------------}
with BitmapImage, BitmapImage.Canvasdo
begin
Height := TextHeight(NumStr)+4;
Width := TextWidth(NumStr)+4;
with Rectdo
begin
Top := 0;
Left := 0;
Bottom := Height;
Right := Width;
end;
FillRect(Rect);
TextOut(2, 2, NumStr);
end;
{---------------------------------------------------------------}
{---------- Write the image to stdout --------------------------}
{---------------------------------------------------------------}
{ Assign the bitmap to the JPEG }
JPEGImage := TJPEGImage.Create;
JPEGImage.Assign(BitmapImage);
JPEGImage.CompressionQuality := 100;
{ Best quality }
{ Create a memory stream to get the contents of the JPEG file. This is
only to determine the size of the JPEG. If I knew how to get the
size of the JPEG right from the JPEGImage, then
the saving to the
memory stream step can be avoided }
MemStream := TMemoryStream.Create;
JPEGImage.SaveToStream(MemStream);
{ Create a stream connected to stdout }
HandleStr := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
{ Write out the content type to stdout }
writeLn('http/1.1 200 ');
writeLn('Date: Thu, 01 Apr 1999 05:07:31 GMT');
writeLn('Last-Modified: Mon, 17 Aug 1998 00:01:33 GMT');
WriteLn('Content-type: image/jpeg');
WriteLn('Content-length: '+intToStr(SizeOf(MemStream)));
WriteLn(' ');
WriteLn(' ');
WriteLn(' ');
WriteLn(' ');
WriteLn('');
{ Write the contents of the memory stream (i.e. the JPEG image) to stdout }
MemStream.SaveToStream(HandleStr);
{ Free everything }
HandleStr.Free;
MemStream.Free;
BitmapImage.Free;
JPEGImage.Free;
end.
program counter;
{$APPTYPE CONSOLE}
uses SysUtils,
Windows,
Graphics,
JPEG,
Classes;
var
BitmapImage: TBitmap;
JPEGImage: TJPEGImage;
NumWidth: Byte;
NumStr: String[10];
Rect: TRect;
MemStream: TMemoryStream;
HandleStr: THandleStream;
CountValue: LongInt;
begin
{ Create the bitmap for the counter }
BitmapImage := TBitmap.Create;
{ Load the Font attributes }
with BitmapImage.Canvas.Fontdo
begin
Name := 'Arial';
Height := 16;
{ Pixels }
Color := clRed;
end;
{ Set the background color }
with BitmapImage.Canvas.Brushdo
begin
Color := clBlack;
end;
NumWidth := 5;
CountValue :=6356;
{ Create the count as a string }
NumStr := IntToStr(CountValue);
if NumWidth > 0 then
while Length(NumStr) < NumWidthdo
NumStr := '0' + NumStr;
{----------------------------------------------------------------}
{----------------- Build the image -----------------------------}
{----------------------------------------------------------------}
with BitmapImage, BitmapImage.Canvasdo
begin
Height := TextHeight(NumStr)+4;
Width := TextWidth(NumStr)+4;
with Rectdo
begin
Top := 0;
Left := 0;
Bottom := Height;
Right := Width;
end;
FillRect(Rect);
TextOut(2, 2, NumStr);
end;
{---------------------------------------------------------------}
{---------- Write the image to stdout --------------------------}
{---------------------------------------------------------------}
{ Assign the bitmap to the JPEG }
JPEGImage := TJPEGImage.Create;
JPEGImage.Assign(BitmapImage);
JPEGImage.CompressionQuality := 100;
{ Best quality }
{ Create a memory stream to get the contents of the JPEG file. This is
only to determine the size of the JPEG. If I knew how to get the
size of the JPEG right from the JPEGImage, then
the saving to the
memory stream step can be avoided }
MemStream := TMemoryStream.Create;
JPEGImage.SaveToStream(MemStream);
{ Create a stream connected to stdout }
HandleStr := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
{ Write out the content type to stdout }
writeLn('http/1.1 200 ');
writeLn('Date: Thu, 01 Apr 1999 05:07:31 GMT');
writeLn('Last-Modified: Mon, 17 Aug 1998 00:01:33 GMT');
WriteLn('Content-type: image/jpeg');
WriteLn('Content-length: '+intToStr(SizeOf(MemStream)));
WriteLn(' ');
WriteLn(' ');
WriteLn(' ');
WriteLn(' ');
WriteLn('');
{ Write the contents of the memory stream (i.e. the JPEG image) to stdout }
MemStream.SaveToStream(HandleStr);
{ Free everything }
HandleStr.Free;
MemStream.Free;
BitmapImage.Free;
JPEGImage.Free;
end.