我有一个带有servermethod的datasnap服务器来加载流,我得到 jpeg错误#53 ,我的目标是获取缩略图大小,我从BLOB fiel获取流,加载到Bitmap对象,然后创建缩略图并将该缩略图转换回流并发送到客户端
加载流后出错
我正在使用 XE7,MSSQL,VLC Datasnap Server
服务器端
function TDSServerMethods.GetImage(proid, Width, Height: Integer; out ImgStream: TStream): Boolean;
var
Bitmap,Bitmap2: FMX.Graphics.TBitMap;
scale: Single;
T:TStream;
stream: TStream;
begin
Result := False;
ImgStream := nil;
WITH SPPROC do
begin
close;
ProcedureName := 'XXXXXX';
Parameters.Clear ;
Parameters.CreateParameter('@ID', ftInteger,pdInput, 0,proid );
Open;
Result := recordcount > 0;
end;
try
T := SPPROC.CreateBlobStream(SPPROC.FieldByName('file'),TBlobStreamMode.bmRead);
T.Seek( 0, TSeekOrigin.soBeginning );
T.Position := 0;
Bitmap := FMX.Graphics.TBitMap.Create;
Bitmap.LoadFromStream( T );
scale := RectF(0, 0, Bitmap.Width, Bitmap.Height).Fit(RectF(0, 0, 200, 200));
Bitmap2 := Bitmap.CreateThumbnail(Round(Bitmap.Width / scale), Round(Bitmap.Height / scale));
stream := TMemoryStream.Create;
stream.Position := 0;
Bitmap2.SaveToStream(stream);
stream.Seek( 0, TSeekOrigin.soBeginning );
stream.Position := 0;
ImgStream := stream
except
Exit(False);
end;
end;
客户端
procedure TFrmMain.Button3Click(Sender: TObject);
var
AImageStream: TStream;
jp: TJPEGImage;
begin
if ( DSServerMethods.GetImage(1038,0, 0, AImageStream)) then
begin
jp := TJPEGImage.Create;
AImageStream.Position := 0;
jp.LoadFromStream( AImageStream ); **here i got jpeg error #53**
Image1.Picture.Assign( jp );
end;
end;
此行中的是错误 jpeg错误#53 jp.LoadFromStream(AImageStream);
但是,如果我使用这个服务器功能一切正常
function TDSServerMethods.GetImage(proid, Width, Height: Integer; out ImgStream: TStream): Boolean;
var
Bitmap,Bitmap2: FMX.Graphics.TBitMap;
scale: Single;
T:TStream;
stream: TStream;
begin
Result := False;
ImgStream := nil;
WITH SPPROC do
begin
close;
ProcedureName := 'XXXXXX';
Parameters.Clear ;
Parameters.CreateParameter('@ID', ftInteger,pdInput, 0,proid );
Open;
Result := recordcount > 0;
end;
try
ImgStream := SPPROC.CreateBlobStream(SPPROC.FieldByName('file'),TBlobStreamMode.bmRead);
except
Exit(False);
end;
end;