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

Re: [Enigmatic semi-solution] Re: Cannot get pixel color from NSBitmapImageRep


  • Subject: Re: [Enigmatic semi-solution] Re: Cannot get pixel color from NSBitmapImageRep
  • From: Ken Ferry <email@hidden>
  • Date: Thu, 1 Oct 2009 11:19:32 -0700

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

  • Follow-Ups:
    • Re: [Enigmatic semi-solution] Re: Cannot get pixel color from NSBitmapImageRep
      • From: "Adam R. Maxwell" <email@hidden>
References: 
 >Cannot get pixel color from NSBitmapImageRep (From: David Hirsch <email@hidden>)
 >Re: Cannot get pixel color from NSBitmapImageRep (From: Dave Keck <email@hidden>)
 >Re: Cannot get pixel color from NSBitmapImageRep (From: David Hirsch <email@hidden>)
 >[Enigmatic semi-solution] Re: Cannot get pixel color from NSBitmapImageRep (From: David Hirsch <email@hidden>)

  • Prev by Date: Re: NSValueTransformer problem with NSTextField update
  • Next by Date: Re: 10.6 specific crash
  • Previous by thread: [Enigmatic semi-solution] Re: Cannot get pixel color from NSBitmapImageRep
  • Next by thread: Re: [Enigmatic semi-solution] Re: Cannot get pixel color from NSBitmapImageRep
  • Index(es):
    • Date
    • Thread