• 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: NSImage/BitmapRep behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage/BitmapRep behavior


  • Subject: Re: NSImage/BitmapRep behavior
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 23 Dec 2006 08:59:24 -0800


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


References: 
 >NSImage/BitmapRep behavior (From: Ben Zotto <email@hidden>)
 >Re: NSImage/BitmapRep behavior (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: NSImage/BitmapRep behavior
  • Next by Date: Re: NSImage/BitmapRep behavior
  • Previous by thread: Re: NSImage/BitmapRep behavior
  • Next by thread: Re: NSImage/BitmapRep behavior
  • Index(es):
    • Date
    • Thread