硕
硕鼠
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是小弟写的程序,完成的功能是将一幅jpg图像输出到IE
procedure TAspTest.WriteImage;
var
jpg:TJPEGImage;
fname:string;
v:OleVariant;
begin
fname:='d:/photo/myphoto/image-01.jpg';
jpg:=TJPEGImage.Create;
jpg.LoadFromFile(fname);
JPEGToVariant(jpg,v);
Response.ContentType:='image/jpeg';
Response.BinaryWrite(v);
end;
procedure TAspTest.JPEGToVariant(aJPEG: TJPEGImage;
var aVariant: OleVariant);
var
Stream : TMemoryStream;
begin
try
Stream := TMemoryStream.Create;
aJPEG.SaveToStream(Stream);
StreamToVariant(Stream, aVariant);
finally
Stream.Free;
end;
end;
procedure TAspTest.StreamToVariant(Stream: TMemoryStream;
var v: OleVariant);
var
p : pointer;
begin
v := VarArrayCreate ([0, Stream.Size - 1], varByte);
p := VarArrayLock (v);
Stream.Position := 0;
Stream.Read (p^, Stream.Size);
VarArrayUnlock(v);
end;
然后通过这种方式调用。
<% Set DelphiASPObj = Server.CreateObject("asptest1.AspTest")
DelphiASPObj.WriteImage
%>
其结果却输出了很多乱码,而不是图像,请各位大侠指点迷津。[]
procedure TAspTest.WriteImage;
var
jpg:TJPEGImage;
fname:string;
v:OleVariant;
begin
fname:='d:/photo/myphoto/image-01.jpg';
jpg:=TJPEGImage.Create;
jpg.LoadFromFile(fname);
JPEGToVariant(jpg,v);
Response.ContentType:='image/jpeg';
Response.BinaryWrite(v);
end;
procedure TAspTest.JPEGToVariant(aJPEG: TJPEGImage;
var aVariant: OleVariant);
var
Stream : TMemoryStream;
begin
try
Stream := TMemoryStream.Create;
aJPEG.SaveToStream(Stream);
StreamToVariant(Stream, aVariant);
finally
Stream.Free;
end;
end;
procedure TAspTest.StreamToVariant(Stream: TMemoryStream;
var v: OleVariant);
var
p : pointer;
begin
v := VarArrayCreate ([0, Stream.Size - 1], varByte);
p := VarArrayLock (v);
Stream.Position := 0;
Stream.Read (p^, Stream.Size);
VarArrayUnlock(v);
end;
然后通过这种方式调用。
<% Set DelphiASPObj = Server.CreateObject("asptest1.AspTest")
DelphiASPObj.WriteImage
%>
其结果却输出了很多乱码,而不是图像,请各位大侠指点迷津。[]