mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 14:16:12 +02:00
LCL, DbImage implements loading stream directly if it doesn't have a known header, WriteHeader property to make writing img header optional
git-svn-id: trunk@43779 -
This commit is contained in:
parent
db5590d263
commit
7ee5132796
@ -974,6 +974,7 @@ Type
|
|||||||
FQuickDraw: Boolean;
|
FQuickDraw: Boolean;
|
||||||
FPictureLoaded: boolean;
|
FPictureLoaded: boolean;
|
||||||
FUpdatingRecord: boolean;
|
FUpdatingRecord: boolean;
|
||||||
|
FWriteHeader: Boolean;
|
||||||
function GetDataField: string;
|
function GetDataField: string;
|
||||||
function GetDataSource: TDataSource;
|
function GetDataSource: TDataSource;
|
||||||
function GetField: TField;
|
function GetField: TField;
|
||||||
@ -1025,6 +1026,7 @@ Type
|
|||||||
property Stretch;
|
property Stretch;
|
||||||
property Transparent;
|
property Transparent;
|
||||||
property Visible;
|
property Visible;
|
||||||
|
property WriteHeader: Boolean read FWriteHeader write FWriteHeader default True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDBCalendar }
|
{ TDBCalendar }
|
||||||
|
@ -104,7 +104,10 @@ begin
|
|||||||
if assigned(FOnDBImageWrite) then
|
if assigned(FOnDBImageWrite) then
|
||||||
OnDBImageWrite(self,s,fe) //Call extermal method to save type of image
|
OnDBImageWrite(self,s,fe) //Call extermal method to save type of image
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
|
if FWriteHeader then
|
||||||
s.WriteAnsiString(fe); //otherwise write file extension to stream
|
s.WriteAnsiString(fe); //otherwise write file extension to stream
|
||||||
|
end;
|
||||||
Picture.Graphic.SaveToStream(s);
|
Picture.Graphic.SaveToStream(s);
|
||||||
finally
|
finally
|
||||||
s.Free;
|
s.Free;
|
||||||
@ -125,6 +128,20 @@ var s : Tstream;
|
|||||||
GraphExt : string;
|
GraphExt : string;
|
||||||
gc : TGraphicClass;
|
gc : TGraphicClass;
|
||||||
AGraphic : TGraphic;
|
AGraphic : TGraphic;
|
||||||
|
CurPos : Int64;
|
||||||
|
|
||||||
|
function LoadImageFromStream: boolean;
|
||||||
|
begin
|
||||||
|
result := (s<>nil);
|
||||||
|
if result then
|
||||||
|
try
|
||||||
|
curPos := s.Position;
|
||||||
|
Picture.LoadFromStream(s);
|
||||||
|
except
|
||||||
|
s.Position := Curpos;
|
||||||
|
result := false;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if not FPictureLoaded then
|
if not FPictureLoaded then
|
||||||
@ -136,35 +153,59 @@ begin
|
|||||||
begin
|
begin
|
||||||
if FDatalink.field is TBlobField then
|
if FDatalink.field is TBlobField then
|
||||||
begin
|
begin
|
||||||
|
|
||||||
if FDatalink.Field.IsNull then
|
if FDatalink.Field.IsNull then
|
||||||
begin
|
begin
|
||||||
Picture.Clear;
|
Picture.Clear;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
s := FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmRead);
|
s := FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmRead);
|
||||||
if (S=Nil) or (s.Size = 0) then
|
if (S=Nil) or (s.Size = 0) then
|
||||||
begin
|
begin
|
||||||
Picture.Clear;
|
Picture.Clear;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
AGraphic := nil;
|
|
||||||
try
|
|
||||||
if assigned(FOnDBImageRead) then
|
|
||||||
OnDBImageRead(self,s,GraphExt) //External method to identify graphic type
|
|
||||||
//returns file extension for graphic type (e.g. jpg)
|
|
||||||
else
|
|
||||||
GraphExt := s.ReadAnsiString; //Read file extension Graphic type from stream
|
|
||||||
|
|
||||||
|
try
|
||||||
|
AGraphic := nil;
|
||||||
|
GraphExt := '';
|
||||||
|
//External method to identify graphic type
|
||||||
|
//returns file extension for graphic type (e.g. jpg)
|
||||||
|
if assigned(FOnDBImageRead) then
|
||||||
|
OnDBImageRead(self,s,GraphExt)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
CurPos := s.Position;
|
||||||
|
try
|
||||||
|
GraphExt := s.ReadAnsiString;
|
||||||
|
except
|
||||||
|
s.Position := CurPos;
|
||||||
|
GraphExt := '';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if GraphExt <> '' then
|
||||||
|
begin
|
||||||
gc := GetGraphicClassForFileExtension(GraphExt);
|
gc := GetGraphicClassForFileExtension(GraphExt);
|
||||||
if assigned(gc) then
|
if gc<>nil then
|
||||||
begin
|
begin
|
||||||
AGraphic := gc.Create;
|
AGraphic := gc.Create;
|
||||||
AGraphic.LoadFromStream(s);
|
AGraphic.LoadFromStream(s);
|
||||||
|
|
||||||
Picture.Assign(AGraphic);
|
Picture.Assign(AGraphic);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
GraphExt := ''; // try next loading direct stream
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if GraphExt = '' then
|
||||||
|
begin
|
||||||
|
if not LoadImageFromStream then
|
||||||
|
Picture.Clear;
|
||||||
|
end;
|
||||||
|
|
||||||
finally
|
finally
|
||||||
if assigned(AGraphic) then AGraphic.Free;
|
AGraphic.Free;
|
||||||
s.Free;
|
s.Free;
|
||||||
end {try}
|
end {try}
|
||||||
|
|
||||||
@ -194,6 +235,7 @@ begin
|
|||||||
ControlStyle:=ControlStyle+[csReplicatable];
|
ControlStyle:=ControlStyle+[csReplicatable];
|
||||||
FAutoDisplay:=True;
|
FAutoDisplay:=True;
|
||||||
FQuickDraw:=true;
|
FQuickDraw:=true;
|
||||||
|
FWriteHeader:=True;
|
||||||
FDataLink:=TFieldDataLink.Create;
|
FDataLink:=TFieldDataLink.Create;
|
||||||
FDataLink.Control:=Self;
|
FDataLink.Control:=Self;
|
||||||
FDataLink.OnDataChange:=@DataChange;
|
FDataLink.OnDataChange:=@DataChange;
|
||||||
|
Loading…
Reference in New Issue
Block a user