Boar eh ... immer und immer wieder ... die sollem mal richtige Entwickler einstellen, die ihr eigenes Produckt selber benutzen.
Du kannst dich aber selber an jedes einzelne ImageFormat wenden und es fragen,
TGraphic.CanLoadFromStream
also TBitmap.CanLoadFromStream, TPngImage.CanLoadFromStream, TJPEGImage.CanLoadFromStream usw.
Ein GetFileFormats.FindFormat wäre natürlich einfacher, aber ..... mähhhhhhhhhh
Delphi-Quellcode:
unit Vcl.Graphics;
implementation <- was soll dieser perverse Scheiß immer?
var
ClipboardFormats: TClipboardFormats =
nil;
FileFormats: TFileFormatsList =
nil;
function GetFileFormats: TFileFormatsList;
begin
if FileFormats =
nil then FileFormats := TFileFormatsList.Create;
Result := FileFormats;
end;
function GetClipboardFormats: TClipboardFormats;
begin
if ClipboardFormats =
nil then ClipboardFormats := TClipboardFormats.Create;
Result := ClipboardFormats;
end;
Delphi-Quellcode:
procedure TPicture.LoadFromFile(const Filename: string);
var
Ext: string;
GraphicClass: TGraphicClass;
Context: TFindGraphicClassContext;
begin
Ext := ExtractFileExt(Filename).Remove(0, 1);
GraphicClass := FileFormats.FindExt(Ext);
Delphi-Quellcode:
procedure TPicture.LoadFromStream(Stream: TStream);
var
GraphicClass: TGraphicClass;
Context: TFindGraphicClassContext;
begin
if Stream.Size - Stream.Position = 0 then
GraphicClass := TBitmap
else
GraphicClass := FileFormats.FindFormat(Stream);
Delphi-Quellcode:
procedure TPicture.LoadFromClipboardFormat(AFormat: Word; AData: THandle;
APalette: HPALETTE);
var
GraphicClass: TGraphicClass;
Context: TFindGraphicClassContext;
begin
GraphicClass := ClipboardFormats.FindFormat(AFormat);
das was öffentlich ist, ist hierfür nicht nutzbar.
Delphi-Quellcode:
function GraphicFilter(GraphicClass: TGraphicClass): string;
var
Filters: string;
begin
GetFileFormats.BuildFilterStrings(GraphicClass, Result, Filters);
end;
function GraphicExtension(GraphicClass: TGraphicClass): string;
var
I: Integer;
begin
for I := GetFileFormats.Count-1 downto 0 do
if TFileFormatType(FileFormats[I]).GraphicClass.ClassName = GraphicClass.ClassName then
begin
Result := TFileFormatType(FileFormats[I]).Extension;
Exit;
end;
Result := '';
end;
function GraphicFileMask(GraphicClass: TGraphicClass): string;
var
Descriptions: string;
begin
GetFileFormats.BuildFilterStrings(GraphicClass, Descriptions, Result);
end;