Re: NSImage/BitmapRep behavior
Re: NSImage/BitmapRep behavior
- Subject: Re: NSImage/BitmapRep behavior
- From: Ben Zotto <email@hidden>
- Date: Sat, 23 Dec 2006 13:22:45 -0500 (EST)
Brilliant. Thank you Shawn, that's exactly the explanation I was after. I confirmed with Preview that the JPEG in question has a 180 DPI. I have some more exploring to do in understanding the treatment of different DPI images, but I think I can hang in from here.
Here's a followup conceptual question though: Why does an image from a digital camera even have a "native" DPI? A camera takes a picture, it has a CCD that can produce an image of a certain resolution (2592x1944 in this case). What is the meaning/relevance of DPI in this case? I do understand that an arbitrary image might have a native DPI as it intends to relate to intentional print or screen rendering size, but where would 180 come from here?
Thanks
Ben
----- Original Message ----
From: Shawn Erickson <email@hidden>
To: Ben Zotto <email@hidden>
Cc: Cocoa CocoaList <email@hidden>
Sent: Saturday, December 23, 2006 11:59:24 AM
Subject: Re: NSImage/BitmapRep behavior
On Dec 23, 2006, at 8:53 AM, Shawn Erickson wrote:
>
> On Dec 23, 2006, at 8:26 AM, Ben Zotto wrote:
>
>> Hi all,
>> I'm hoping someone can help me understand the following behavior
>> so I can better understand what's happening in some of my image
>> management code.
>>
>> I load a large JPEG (pretty standard, from a digital camera) into
>> an NSImage via -initWithContentsOfFile:. The JPEG has a
>> resolution of 2592 x 1944. This is the same as the pixelsWide/
>> pixelsHigh given by the NSBitmapImageRep representation. I have
>> not yet drawn the NSImage into anything, so it has not yet become
>> a cached image. But the -size method on NSImage returns a size of
>> 1036.800049x777.599976. Why? This size doesn't seem to be some
>> multiple of the pixel resolution of the image (or any relation to
>> the size of the view which it will later be drawn into).
>>
>> I ran some NSLogging on the NSImage and its reps before and after
>> drawing the image. Here are the results:
>> ****
>> NSImage size: 1036.800049 x 777.599976
>> rep: NSBitmapImageRep 0x3568b0 Size={1036.8, 777.6}
>> ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=24 Pixels=2592x1944
>> Alpha=NO Planar=NO Format=0
>> NSImageRep pix: 2592 x 1944
>
> NSImages define size in terms of user space coordinates which is 72
> points per inch. NSBitmapImageReps & NSCachedImageReps define size
> in terms of pixels.
>
> The difference you see between NSImage size and the size returned
> by NSBitmapImageRep comes from the DPI information imbedded in the
> image you are opening. In this case the source image appears to be
> set to 180 DPI.
I meant to note... If you don't want NSImage to honor the DPI of the
image then simply set the size of the image to the size (pixelsWider/
pixelsHigh) returned by the bitmap rep. Doing that forces a one-to-
one mapping between image points and image pixels (not always what
you want so make sure you are doing this for the right reasons).
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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