LCL, DbImage, fix loading streams without header

git-svn-id: trunk@43781 -
This commit is contained in:
jesus 2014-01-22 18:18:52 +00:00
parent 05d2879059
commit 0e4bb71842

View File

@ -143,6 +143,25 @@ var s : Tstream;
end; end;
end; end;
procedure GraphExtToClass;
begin
gc := GetGraphicClassForFileExtension(GraphExt);
end;
procedure ReadImageHeader;
begin
CurPos := s.Position;
try
GraphExt := s.ReadAnsiString;
except
s.Position := CurPos;
GraphExt := '';
end;
GraphExtToClass;
if gc=nil then
s.Position := CurPos;
end;
begin begin
if not FPictureLoaded then if not FPictureLoaded then
begin begin
@ -170,35 +189,37 @@ begin
try try
AGraphic := nil; AGraphic := nil;
GraphExt := ''; GraphExt := '';
//External method to identify graphic type
//returns file extension for graphic type (e.g. jpg)
if assigned(FOnDBImageRead) then if assigned(FOnDBImageRead) then
OnDBImageRead(self,s,GraphExt) begin
// External method to identify graphic type
// returns file extension for graphic type (e.g. jpg)
// If user implements OnDBImageRead, the control assumes that
// the programmer either:
//
// -- Returns a valid identifier that matches a graphic class and
// the remainder of stream contains the image data. An instance of
// of graphic class will be used to load the image data.
// or
// -- Returns an invalid identifier that doesn't match a graphic class
// and the remainder of stream contains the image data. The control
// will try to load the image trying to identify the format
// by it's content
//
// In particular, returning an invalid identifier while the stream has
// a image header will not work.
OnDBImageRead(self,s,GraphExt);
GraphExtToClass;
end
else else
begin ReadImageHeader;
CurPos := s.Position;
try
GraphExt := s.ReadAnsiString;
except
s.Position := CurPos;
GraphExt := '';
end;
end;
if GraphExt <> '' then if gc<>nil then
begin begin
gc := GetGraphicClassForFileExtension(GraphExt); AGraphic := gc.Create;
if gc<>nil then AGraphic.LoadFromStream(s);
begin Picture.Assign(AGraphic);
AGraphic := gc.Create; end
AGraphic.LoadFromStream(s); else
Picture.Assign(AGraphic);
end
else
GraphExt := ''; // try next loading direct stream
end;
if GraphExt = '' then
begin begin
if not LoadImageFromStream then if not LoadImageFromStream then
Picture.Clear; Picture.Clear;