Vampyre Imaging Library Forum

Imaging Category => Help & Questions => Topic started by: davem on 1 November 2011, 11:44:59

Title: JPG Resolution
Post by: davem on 1 November 2011, 11:44:59
Do I understand from this topic http://galfar.vevb.net/imaging/smf/index.php/topic,283.0.html (http://galfar.vevb.net/imaging/smf/index.php/topic,283.0.html) that the library supports the print resolution of JPEGs (in pixels per inch or pixels per cm)? How to set it up? Thanks!
Title: Re: JPG Resolution
Post by: Galfar on 1 November 2011, 23:33:33
You can get print resolution from JPEGs (provided that this info is embedded inside) using metadata framework.
It's not stored in image itself so you need to keep track of it if you want to later save the values that were loaded.

Code (pascal) Select
type
  // defined in Imaging.pas
  TResolutionUnit = (
    ruSizeInMicroMeters, // value is pixel size in micrometers
    ruDpi,               // value is pixels/dots per inch
    ruDpm,               // value is pixels/dots per meter
    ruDpcm               // value is pixels/dots per centimeter
  );

var
  XRes, YRes: Single;
  ResUnit: TResolutionUnit;

... load image ...

ResUnit := ruDpi;
if GlobalMetadata.GetPhysicalPixelSize(ResUnit, XRes, YRes) then
begin
  ... print resolution present, do something with it
end;

... do something with image
GlobalMetadata.SetPhysicalPixelSize(ResUnit, XRes, YRes, True)
... save image


Checkout TMetadata class in Imaging.pas for implementation details.