Re: NSImage and Photoshop jpegs
Re: NSImage and Photoshop jpegs
- Subject: Re: NSImage and Photoshop jpegs
- From: Marcel Weiher <email@hidden>
- Date: Thu, 20 Mar 2003 23:45:50 +0100
On Thursday, March 20, 2003, at 10:44 Uhr, Alesh Slovak wrote:
I am developing a Cocoa app which needs to open jpeg files. It seems,
however, that jpeg files created by Photoshop and then opened with
initWithContentsOfFile have incorrect sizes.
Could it be you are confusing "pixels" with "size"?
For example I opened an image with a resolution of 1280 x 1920 but
when I opened it the NSImage reported it as being only 288 x 432
pixels.
NSImage doesn't really report pixel sizes, it reports "physical" size.
NSImage is a cover for a variety of graphics formats, some of which do
not have pixels, and are also resolution-independent. Also, the
"1280x1920" wouldn't be the "resolution", but the pixel size.
Is this desired behaviour?
Yes.
Does anyone know what is going on here?
Yes. Your images have a resolution of 320 dpi. At 320 dpi and a size
of 288 x 432 (Postscript) points (not pixels), you get 1280 x 1920
pixels (not points, not "resolution").
There are 72 Postscript points in an inch, so the dimensions of your
image in inches are 4 x 6.
Is there any other way of getting the resolution of an image, other
than from an NSImage instance?
In general, use NSBitmapImageRep for image manipulation. NSImage is
really only useful for simple icon drawing. NSBitmapImageRep has
methods that tell you the pixel-size:
-(int)pixelsWide, -(int)pixelsHigh
These will tell you the number of pixels. But in a device-independent
imaging model, the number of pixels doesn't tell you anything about the
actual size. For this reason, NSBitmapImageRep also has the
-(NSize)size method, which gives the size in Postscript points (which
are also the basic unit of measurment for PDF/Quartz). To get the
resolution:
resolution (in dpi) = (pixels / size) * 72
Hope this helps,
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.