Hi David,
Oh, yes, you're right.  In the bitmapData, the first row is the top row.
 -getPixelAtX:y:, -setPixelAtX:y:, -getColorAtX:y: and setColorAtX:y: are
the same.  The first row is the top.  Sorry that's confusing.

-isFlipped: is not a property of NSBitmapImageRep, that's on NSImage.  The
above is true always.

You might also want to take a look at the section "NSBitmapImageRep:
CoreGraphics impedence matching and performance notes" in the AppKit release
notes<http://developer.apple.com/mac/library/releasenotes/Cocoa/AppKit.html>.
 We don't recommend poking at the pixels of an NSBitmapImageRep, but if
you're going to and you aren't just poking one pixel, you're better off
using a bulk interface.  Message dispatch overhead is too high a proportion
of the work to be done with the one-by-one approach.

A batch alternative is to draw into an appropriately sized bitmap whose
pixel format you know and understand.  That's effectively copying out all
the color info you're interested in in one swoop.  Then you can look at that
data.  This is demonstrated in that relnotes passage.

-Ken
Cocoa Frameworks

On Thu, Oct 1, 2009 at 8:52 AM, David Hirsch <[email protected]> wrote:

> Well, I can work around it but I don't understand this at all.  Apparently
> the context is flipped, or getPixelAtX:y: is flipped, or something.  In this
> code, the first NSLog statement gives all zeros, and the second gives the
> intended red color.  However flipped returns NO.  Any ideas as to what the
> heck is going on here?
>
>        offscreenRep = [[NSBitmapImageRep alloc]
> initWithBitmapDataPlanes:nil
>
>                                       pixelsWide:500
>
>                                       pixelsHigh:300
>
>                                    bitsPerSample:8
>
>                              samplesPerPixel:4
>
>                                             hasAlpha:YES
>
>                                             isPlanar:NO
>
>                               colorSpaceName:NSCalibratedRGBColorSpace
>
>                                     bitmapFormat:0
>
>                                      bytesPerRow:0
>
>                                     bitsPerPixel:0];
>        [offscreenRep retain];
>        [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(0, 0, 41, 259)];
>        NSLog(@"%@", [offscreenRep colorAtX:40  y:40]);
>        [NSBezierPath fillRect:NSMakeRect(0, 0, 41, 261)];
>        NSLog(@"%@", [offscreenRep colorAtX:40  y:40]);
>        BOOL flipped =  [[NSGraphicsContext currentContext] isFlipped];
>
>
> -Dave
>
>
> _______________________________________________
>
> 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/kenferry%40gmail.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