Re: How to get image resolution?



{------------------------------------------------------------------------------
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;
.



Relevant Pages

  • Re: Sharpness in Tiff Scans
    ... the resolution, the uglier the scan will look. ... I agree with others that JPG vs. TIF is entirely ... I've started with a Nikon film scanner at 4000 dpi and 16 bit color ...
    (comp.periphs.scanners)
  • Re: 3D Rendered Dental X-Ray Video Clip I made?
    ... you cannot change the resolution. ... If all images were captured at 600 dpi, your database would get huge twice ... >>> This X-Ray is a 512x768 pixel digital radiograph from a Trophy RVG3 ... >>> It can render at various precisions - depending on what you want to see ...
    (sci.med.dentistry)
  • Re: PNG format and DPI
    ... if I save it as a PNG the resolution drops to 72 DPI! ... I then view the PNG image in Bridge. ...
    (alt.graphics.photoshop)
  • Re: Mac Word 2004 Templates yield HUGE filesizes when used by Windows machines?
    ... Unless you are still using the SE30, you should be specifying 96 dpi, ... native resolution of the target device so nothing has to do any resampling. ... Scalable Vector Graphics. ... If the source picture is a photograph, you really need to use JPEG. ...
    (microsoft.public.mac.office.word)
  • Re: Looking for advice for a good Digital Ice 35mm slide scanner
    ... I will scan at whatever lower resolution gives me something ... mega pixels of 3600 DPI. ... simply no point to a 4800 DPI scan on slides that don't have ... whatever DPI the scanner supports, evaluate ICE, and evaluate ...
    (rec.photo.digital)