• 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
Cannot get pixel color from NSBitmapImageRep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Cannot get pixel color from NSBitmapImageRep
      • From: Dave Keck <email@hidden>
    • Re: Cannot get pixel color from NSBitmapImageRep
      • From: Jonathan Hess <email@hidden>
  • Next by Date: Re: NSApplication's behavior
  • Next by thread: Re: Cannot get pixel color from NSBitmapImageRep
  • Index(es):
    • Date
    • Thread