产品名称:医学影像和数据处理与通讯软件 型号:浩连 版本:1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

74 lines
1.5 KiB

unit FileToImage;
interface
uses Windows, Classes, ExtCtrls, Graphics, SysUtils, GraphicEx;
procedure GetImageFromFile(sFileName: string; var tBMP: TBitmap);
function GetSizeFromFile(aFileName: string):Integer;
implementation
function GetSizeFromFile(aFileName: string):Integer;
var
fHandle : Integer;
begin
Result := 0;
try
fHandle := FileOpen(aFileName, 0);
if fHandle > 0 then
begin
Result := GetFileSize(fHandle, nil);
FileClose(fHandle);
end;
except
end;
end;
procedure GetImageFromFile(sFileName: String; var tBMP: TBitmap);
var
IExtensions : TStringList;
PPicture : TPicture;
i : Integer;
sExt : String;
begin
if FileExists(sFileName)=False then
Exit;
IExtensions := TStringList.Create;
PPicture := TPicture.Create;
try
FileFormatList.GetExtensionList(IExtensions);
for i := 0 to IExtensions.Count - 1 do
IExtensions[I] := '.' + UpperCase(IExtensions[I]);
IExtensions.Sort;
except
end;
sExt := ExtractFileExt(sFileName);
//if IExtensions.Find(sExt, i) then
begin
try
PPicture.LoadFromFile(sFileName);
if PPicture.Graphic is TBitmap then
tBMP.Assign(PPicture)
else
begin
with tBMP do
begin
PixelFormat := pf24Bit;
Width := PPicture.Width;
Height := PPicture.Height;
Canvas.Draw(0, 0, PPicture.Graphic);
end;
end;
except
// no exceptions please, just ignore invalid images
end;
end;
PPicture.Free;
IExtensions.Free;
end;
end.