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 protected]
> http://www.davehirsch.com
> voice: (360) 389-3583
> aim: [email protected]
> vCard: http://almandine.geol.wwu.edu/~dave/personal/DaveHirsch.vcf
> ============================
> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/jhess%40apple.com
> 
> This email sent to [email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to