Re: Getting colour data at specified point in an NSImage
Re: Getting colour data at specified point in an NSImage
- Subject: Re: Getting colour data at specified point in an NSImage
- From: Michael Watson <email@hidden>
- Date: Tue, 13 Mar 2007 17:47:34 -0400
Oops, already spotted a mistake. This should be my initializer:
bitmapRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:imageSize.width
pixelsHigh:imageSize.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:YES
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0 // let NSBitmapImageRep take care of this
bitsPerPixel:32];
(However, I'm still not doing something correctly in my original
problem.)
--
mikey
On 13 Mar, 2007, at 17:11, Michael Watson wrote:
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