• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Setting DPI of image data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting DPI of image data


  • Subject: Re: Setting DPI of image data
  • From: Heinrich Giesen <email@hidden>
  • Date: Fri, 11 Jul 2008 11:13:34 +0200


On 11.07.2008, at 05:37, Graham Cox wrote:

I'm using NSBitMapImageRep's -representationUsingType:properties:
method to convert data to JPEG, TIFF, etc. I'd like to be able to
specify the DPI of the image. I can calculate the right number of
pixels needed for a given DPI OK, but the image always comes up as
having 72 dpi when opened in another app. Is there a way to set this
property at this level, or am I forced to drop down into Image I/O?


If you create image data of Type jpeg, tiff, png, etc from a sourceRep
(NSBitMapImageRep) with -representationUsingType:properties: these data
contain the number of pixels *and* the resolution of the sourceRep.
If you want a special resolution you have to set that value in the
sourceRep. But you can't set the resolution directly in NSBitMapImageRep
with something like -setResolutionX:resolutionY: You have to set the
size of the rep! Because of:
size.width = 72.0*pixelsWide / resolutionX
size.height = 72.0*pixelsHigh / resolutionY
(size has the dimension of a length and the unit 1/72 inch;
resolution has the dimension "dots per length" and the
unit "dots per inch"; pixelsWide, pixelsHigh are dimensionless numbers.)
there is no difference between setting the resolution and setting
the size.


If the rep shall have a resolution of 72 dpi, the size must be set
to (pseudocode) size = (pixelsWide, pixelsHigh); (Because this is the
default, you need not do so.) This is a bit confusing. A lot
of programmers think that size and number of pixels are one and the
same with different words. The values are indead *numerically* the same,
but only for a resolution of 72 dpi.

If the rep shall have a resolution of 144 dpi, the size must be set
to size = (pixelsWide/2.0, pixelsHigh/2.0);

For these settings in my programs I use a category for NSBitMapImageRep
which does the job.

One other point. Let's have a sourceRep with a resolution of 100 dpi
and this sourceRep is stored as png-file (data come from
-representationUsingType:properties:) then Preview.app will show a
resolution of 99.9998 dpi which is correct! This happens because in
png-files the resolution is stored as int with the unit "dots per meter":
res [dots per meter] = (int)(10000 / 2.54) = 3937
or:
res [dots per inch] = 3937*0.0254 = 99.9998


	Heinrich

--
Heinrich Giesen
email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Setting DPI of image data
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Setting DPI of image data
  • Next by Date: Re: How do I copy a view?
  • Previous by thread: Re: Setting DPI of image data
  • Next by thread: Re: Setting DPI of image data
  • Index(es):
    • Date
    • Thread