Cannot get pixel color from NSBitmapImageRep
Cannot get pixel color from NSBitmapImageRep
- Subject: Cannot get pixel color from NSBitmapImageRep
- From: David Hirsch <email@hidden>
- Date: Thu, 01 Oct 2009 01:22:42 -0700
In the code below, the TIFF gets saved correctly (transparent but for
the red square), but when I query the pixel at (40,40) which should be
in the middle of the red square, I get a black pixel (r==g==b==a==0.0):
offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:canvasSizeH
pixelsHigh:canvasSizeV
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:0
bytesPerRow:0
bitsPerPixel:0];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:offscreenRep]];
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
[[NSColor colorWithCalibratedRed:0.5 green:0 blue:0 alpha:1.0] set];
[NSBezierPath fillRect:NSMakeRect(10, 10, 100, 100)];
NSData* TiffData = [offscreenRep TIFFRepresentation];
[TiffData writeToFile:@"/Users/dave/Desktop/temp.tiff" atomically:YES];
NSColor *pixelColor = [offscreenRep colorAtX:40 y:40];
float r,g,b,a;
[pixelColor getRed:&r green:&g blue:&b alpha:&a];
Thanks,
Dave
============================
Dave Hirsch
Associate Professor
Department of Geology
Western Washington University
persistent email: email@hidden
http://www.davehirsch.com
voice: (360) 389-3583
aim: email@hidden
vCard: http://almandine.geol.wwu.edu/~dave/personal/DaveHirsch.vcf
============================
_______________________________________________
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