• 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: Resolution of an NSImage(Rep)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Resolution of an NSImage(Rep)?


  • Subject: Re: Resolution of an NSImage(Rep)?
  • From: Brian Postow <email@hidden>
  • Date: Thu, 5 Aug 2010 13:43:07 -0400

On Aug 5, 2010, at 1:15 PM, Quincey Morris wrote:

> On Aug 5, 2010, at 08:45, Brian Postow wrote:
>
>> Given a bunch of bitmap data, and a resolution, how do I create an NSImage (or CGImage or CGImageSource) with the correct resolution?
>>
>> Currently, I'm doing:
>>
>>      CGDataProviderRef provider= CGDataProviderCreateWithData(NULL, (UInt8*)data, bytesPerRow * length, NULL);
>>
>> 	[...]
>>
>> 	NSData* imgData = [NSMutableData data];
>> 	CGImageDestinationRef dest = CGImageDestinationCreateWithData
>> 		(imgData, kUTTypeTIFF, 1, NULL);
>> 	CGImageDestinationAddImage(dest, cgImg, NULL);
>> 	CGImageDestinationFinalize(dest);
>> 	NSImage* img = [[NSImage alloc] initWithData: imgData];
>>
>>
>> now, it appears that CGImageDestination takes only a NULL argument for the dictionary.. and width and length are in pixels, not points or inches.  At what point in this process am I supposed to add the resolution into this process?
>
> Yes, the CGImage has no resolution, only a pixel size. So you add in the resolution at the very end, after creating the NSImage:
>
> 	img.size = NSMakeSize (widthInPoints, heightInPoints);
>

oh, so size is in points? I assumed it was in pixels. The documentation just says "the size of the receiver" which my boss assumed was in pounds B-)

> where the dimensions in points are computed from the pixel dimensions and the known resolution.
>
> Actually, after looking at the documentation again, doing it exactly this way seems slightly risky (if the NSImage is set to do scaling automatically, for example). I think what you really should do is to create a NSImageRep from the CGImage, the set the NSImageRep 'size' property to the correct size in points, then add that image rep to a new "empty" NSImage.
>
>
> _______________________________________________
>
> 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
>

Brian Postow
Senior Software Engineer
Acordex Imaging Systems

_______________________________________________

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: Resolution of an NSImage(Rep)?
      • From: Quincey Morris <email@hidden>
References: 
 >Resolution of an NSImage(Rep)? (From: Brian Postow <email@hidden>)
 >Re: Resolution of an NSImage(Rep)? (From: Graham Cox <email@hidden>)
 >Re: Resolution of an NSImage(Rep)? (From: Brian Postow <email@hidden>)
 >Re: Resolution of an NSImage(Rep)? (From: Brian Postow <email@hidden>)
 >Re: Resolution of an NSImage(Rep)? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: calling a function in one class from another
  • Next by Date: Question about color
  • Previous by thread: Re: Resolution of an NSImage(Rep)?
  • Next by thread: Re: Resolution of an NSImage(Rep)?
  • Index(es):
    • Date
    • Thread