mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 03:39:18 +02:00
LCL, DbImage, fix loading streams without header
git-svn-id: trunk@43781 -
This commit is contained in:
parent
05d2879059
commit
0e4bb71842
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user