Re: How to get image resolution?
- From: Mat Ballard <mat@xxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 09:34:40 +1000
{------------------------------------------------------------------------------
Function: GetGraphicResolution
Description: This Gets the Resolution of a Graphic
Author: Mat Ballard
Date created: 08/20/2006
Date modified: 11/21/2006 by Mat Ballard
Purpose: Graphic manipulation
Return Value: Single (dpi)
Known Issues: returns DPI even if graphic is in LPC - for consistency
------------------------------------------------------------------------------}
function GetGraphicResolution(AGraphic: TGraphic): Single;
var
PNG: TPngObject; // TPngImage
Chunk: TChunk;
TIF: EnTifGr.TTiffGraphic; // Envision Image Library
begin
{GIFs and JPEGs don't have resolution, so return screen resolution for
TGifImage, TJpegImage, and TPngObject without a ChunkPhys:}
Result := Screen.PixelsPerInch;
if (AGraphic is TBitmap) then
begin
Result := GetBmpDpi(TBitmap(AGraphic));
end else if (AGraphic is TMetafile) then begin
Result := _MM_PER_INCH * TMetafile(AGraphic).Width /
TMetafile(AGraphic).MMWidth;
end else if (AGraphic is TPngObject) then begin
PNG := TPngObject(AGraphic);
Chunk := PNG.Chunks.FindChunk(TChunkpHYs);
if Assigned(Chunk) then
begin
if (TChunkPhys(Chunk).UnitType = utMeter) then
Result := TChunkPhys(Chunk).PPUnitX / _INCHES_PER_METER;
// ChunkpHYs.PPUnitX := Round(Resolution * _INCHES_PER_METER);
end;
{$IFDEF TIF}
end else if (AGraphic is EnTifGr.TTiffGraphic) then begin
TIF := EnTifGr.TTiffGraphic(AGraphic);
if (TIF.ResolutionUnit = ruInch) then // ie: dpi
Result := TIF.XResolution
else if (TIF.ResolutionUnit = ruCentimeter) then // metric lpc
Result := _CM_PER_INCH * TIF.XResolution;
{$ENDIF}
end;
end;
.
- References:
- How to get image resolution?
- From: Grant Alperstein
- How to get image resolution?
- Prev by Date: Re: Problem selecting text with pBear's THTMLViewer component
- Next by Date: Re: Statistical library recommendation - many thanks
- Previous by thread: Re: How to get image resolution?
- Next by thread: ABC for Delphi .net components
- Index(es):
Relevant Pages
|