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

Re: Cannot get pixel color from NSBitmapImageRep


  • Subject: Re: Cannot get pixel color from NSBitmapImageRep
  • From: Jonathan Hess <email@hidden>
  • Date: Thu, 1 Oct 2009 01:28:28 -0700

On Oct 1, 2009, at 1:22 AM, David Hirsch wrote:

> 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];

This is just as guess, but perhaps there's an issue with the drawing not being completed and flushed back to the bitmap buffer. Have you tried restoring the graphics context prior to querying for the pixel value?

Jon Hess

>
> 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

_______________________________________________

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

References: 
 >Cannot get pixel color from NSBitmapImageRep (From: David Hirsch <email@hidden>)

  • Prev by Date: Re: NSApplication's behavior
  • Next by Date: Re: [iPhone] Application running for the very first time...
  • Previous by thread: Cannot get pixel color from NSBitmapImageRep
  • Next by thread: Re: Cannot get pixel color from NSBitmapImageRep
  • Index(es):
    • Date
    • Thread