• 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 from a url
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage from a url


  • Subject: Re: NSImage from a url
  • From: Nicko van Someren <email@hidden>
  • Date: Mon, 25 Apr 2005 18:38:58 +0100

On 25 Apr 2005, at 18:13, Graham wrote:

Mostly there is no problem, but for some images, the resulting NSImage size is smaller than the image at the url location. This is easily verified by entering the url in a browser and looking at the image.
This image: http://photos7.flickr.com/10756720_fe91e8456a.jpg is 500 pixels wide when you view it in the browser, but when I create an NSImage from it, the NSImage is only 180 pixels wide. Using the exact same code most images come out the correct size, such as this one: http://photos7.flickr.com/10424399_6f73976e6e.jpg which is 500 wide and creates an NSImage 500 wide.

Open both images in Preview and press Command-I. You will find that the first image registers 200 DPI whereas the second image registers 72 DPI. The co-ordinate system in Cocoa works at 72 DPI by default so the size of the first image is only 180 units.


You can find out the number of pixels high and wide a bitmap image representation is designed to be by calling pixelsHigh and pixelsWide on the image representation. You can then reset the size to be the pixel size, thereby ignoring the DPI setting. Note that you need to be a little careful doing this to make sure that you're not getting a representation that is some cached copy at a different resolution but in general if you do this immediately after loading something that is known to be a bitmap image and before you have drawn anything you should be OK. Of course NSImage initWithContentsOfURL works on all sorts of non-bitmap files like PDF and EPS; approach with cation.

	Nicko

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSImage from a url (From: Graham <email@hidden>)

  • Prev by Date: Re: BUG?: Multiple Inheritance and DO
  • Next by Date: Drawing polygons and keeping a list of them...
  • Previous by thread: Re: NSImage from a url
  • Next by thread: Drawing polygons and keeping a list of them...
  • Index(es):
    • Date
    • Thread