• 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
Getting colour data at specified point in an NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting colour data at specified point in an NSImage


  • Subject: Getting colour data at specified point in an NSImage
  • From: Michael Watson <email@hidden>
  • Date: Tue, 13 Mar 2007 17:11:41 -0400

Funny little problem I'm having:

I'm creating an NSBitmapImageRep and then creating an NSImage. I add the bitmap rep to the NSImage, lock focus on the bitmap rep, and then fill it with a colour generated via NSColor. I then ask for a component value from a point in the bitmap rep, but it always returns 0.0. What am I doing incorrectly?

Example code:

NSSize imageSize = NSMakeSize(800, 600);

bitmapRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:imageSize.width
pixelsHigh:imageSize.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:YES
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:800
bitsPerPixel:32];

image = [[NSImage alloc] initWithSize:imageSize];
[image addRepresentation:bitmapRep];

[image lockFocusOnRepresentation:bitmapRep];
[[NSColor colorWithCalibratedWhite:1.0 alpha:1.0] set];
NSRectFillUsingOperation(NSMakeRect(0, 0, imageSize.width, imageSize.height), NSCompositeCopy);
[image unlockFocus];

float alf = [[bitmapRep colorAtX:10 y:10] alphaComponent];
NSLog(@"%f", alf);




--
mikey
"If you can't convince them, confuse them." - Harry S. Truman


_______________________________________________

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


  • Follow-Ups:
    • Re: Getting colour data at specified point in an NSImage
      • From: Michael Watson <email@hidden>
  • Prev by Date: Re: Adding AppleScript support to a Core Data application
  • Next by Date: Re: Getting colour data at specified point in an NSImage
  • Previous by thread: Re: Sharing a content view between two NSWindows
  • Next by thread: Re: Getting colour data at specified point in an NSImage
  • Index(es):
    • Date
    • Thread