判斷記憶體流中的圖檔格式
代碼如下:
// 從記憶體流中判斷圖檔格式
procedure TForm1.BitBtn4Click(Sender: TObject);
var
MyImage:TMemoryStream;
Buffer:Word;
i: integer ;
begin
if OpenDialog1.Execute then
begin
MyImage: = TMemoryStream.Create;
MyImage.LoadFromFile(OpenDialog1.FileName);
MyImage.Position : = 0 ;
if MyImage.Size = 0 then
begin
// ERR
ShowMessage( ' ERR');
MyImage.Free;
Exit ;
end ;
MyImage.ReadBuffer(Buffer, 2 );
if Buffer = $4D42 then
begin
// BMP
ShowMessage( ' BMP');
end
else if Buffer = $D8FF then
begin
// JPEG
ShowMessage( ' JPEG');
end
else if Buffer = $ 4947 then
begin
// GIF
ShowMessage( ' GIF');
end
else if Buffer = $050A then
begin
// PCX
ShowMessage( ' PCX');
end
else if Buffer = $ 5089 then
begin
// PNG
ShowMessage( ' PNG');
end
else if Buffer = $ 4238 then
begin
// PSD
ShowMessage( ' PSD');
end
else if Buffer = $A659 then
begin
// RAS
ShowMessage( ' RAS');
end
else if Buffer = $DA01 then
begin
// SGI
ShowMessage( ' SGI');
end
else if Buffer = $ 4949 then
begin
// TIFF
ShowMessage( ' TIFF');
end
else
begin
// ERR
ShowMessage( ' ERR');
end ;
MyImage.Free;
end ;
end ;