Problem/Question/Abstract:
How to get the resolution (in DPI) of a *.jpg image
Answer:
procedure GetResJpg(JPGFile: string);
const
BufferSize = 50;
var
Buffer: string;
Index: integer;
FileStream: TFileStream;
HorzRes, VertRes: Word;
DP: Byte;
Measure: string;
begin
FileStream := TFileStream.Create(JPGFile, fmOpenReadWrite);
try
SetLength(Buffer, BufferSize);
FileStream.Read(buffer[1], BufferSize);
Index := Pos('JFIF' + #$00, buffer);
if Index > 0 then
begin
FileStream.Seek(Index + 6, soFromBeginning);
FileStream.Read(DP, 1);
case DP of
1: Measure := 'DPI';
2: Measure := 'DPC';
end;
FileStream.Read(HorzRes, 2);
HorzRes := Swap(HorzRes);
FileStream.Read(VertRes, 2);
VertRes := Swap(VertRes);
end;
finally
FileStream.Free;
end;
end;
Nincsenek megjegyzések:
Megjegyzés küldése