DPI打印的时候才用的到
//获得BMP分辨率
function GetBmpDPI(Bitmap: TBitmap): LongInt;
var
Stream: TMemoryStream;
Data: Word;
A: Double;
begin
Result := 0;
Stream := TMemoryStream.Create;
try
Bitmap.SaveToStream(Stream);
Stream.Position := 38;
if Stream.Read(Data,2) = 2 then
begin
A := Data;
Result := Round(A / 39.370079);
end;
finally
Stream.Clear;
Stream.Free;
end;
end;
//获得JPEG分辨率,只能获得delphi创建的jpg文件
function GetJPEGDPI(JPEGImage:TJPEGImage): LongInt;
const
BufferSize = 50;
var
Buffer : STRING;
Stream : TMemoryStream;
Data : Word;
begin
Result := 0;
Stream := TMemoryStream.Create;
try
JPEGImage.SaveToStream(Stream);
SetLength(Buffer, BufferSize);
Stream.Seek(0,soFromBeginning);
Stream.Read(buffer[1], BufferSize);
if POS('JFIF'+#$00, buffer)>0 then begin //处理JFIF格式
Stream.Position := $E;
if Stream.Read(Data,2) = 2 then
Result:=Swap(Data);
if Result<72 then Result:=72;
end else Result:=72;
finally
Stream.Clear;
Stream.Free;
end;
end;