Wednesday 18 April 2007, 10:49
function SaveJPEG(dsDestination : TDataSet; Img : TImage; Fld : String) : Integer;
var
JPEG : TJpegImage;
BLStream : TBlobStream;
begin
Jpeg := TJpegImage.Create;
try
//Every image should be converted as JPEG
Jpeg.CompressionQuality := 75;
Jpeg.Assign(Img.Picture.Graphic);
BlStream := TBlobStream.Create(dsDestination.FieldByName(Fld) as =
TBLOBField, bmReadWrite);
Try
//Saving image...
Jpeg.SaveToStream(blStream);
Result := 1;
finally
BLStream.Free;
end;
finally
Jpeg.Free;
end;
end;
function GetJPEG(dsSource : TDataSet; Field : String; var Img : TImage) : Integer;
var
JPEG : TJpegImage;
BLStream : TBlobStream;
begin
Jpeg :=TJPEGImage.Create;
try
//If field is not empty, we can proceed with JPEG retrieve
if not dsIzvor.FieldByName(Polje).isNull then begin
BLStream :=TBLOBStream.Create(dsSource.FieldByName(Fld) as =
TBLOBField, bmRead);
try
BLStream.Position := 0;
try
Jpeg.LoadFromStream(BLStream);
Img.Picture.Assign(JPEG);
Result := 1;
except
end;
finally
BLStream.Free;
end;
end; //if not isNull
finally
Jpeg.Free;
end;
end;