• 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: Pick color value from any pixel on screen
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pick color value from any pixel on screen


  • Subject: Re: Pick color value from any pixel on screen
  • From: Cybereer <email@hidden>
  • Date: Wed, 30 Nov 2005 15:30:30 -0500

Yeah, it's used to be possible to make a NSBitmapImageRep by using initWithFocusedViewRect in conjunction with a transparent window, but Tiger has apparently broken that.

Now you have to use either QuickDraw or OpenGL. The following is from John Walter on the Quartz list:

Take a look at the Quartz Service Reference in the doc. If I remember
correctly, you have to find the main display (if you don't have a
second monitor and/or graphic card there will be only one), then
capture it (and release it after you're done). There is at least one
function that return the base address of the framebuffer, and I think
there is one that returns the framebuffer adress for a given (x, y)
pixel position.

Don't forget to obtain the display parameters such as bytes par pixel,
display size, color depth, etc. so that you can get the right color
and alpha value for a pixel. For instance, if your display is in a
32bits color depth (4 bytes, I think one for alpha, 3 for RGB), you'll
have to read the next 4 bytes starting from your current position in
the framebuffer to get the correct pixel color.

There are other ways to achieve your goal but I'm only familiar with
this one. I strongly suggest you look at this post :
http://www.cocoabuilder.com/archive/message/cocoa/2005/8/13/144220

There are three examples of screen captures, even one that use OpenGL
(it seems to be the fastest of all three, but maybe the most resource
consuming also (only a guess) ?)


On Nov 30, 2005, at 6:42 AM, Uli Kusterer wrote:

Am 29.11.2005 um 21:40 schrieb Cybereer:
Hi everyone, I am new to this list, and have a naive Cocoa question for those who know:

Since NSReadPixel doesn't seem to work across windows, what's the official or best way to read a pixel anywhere on screen? Furthermore, what's most efficient method for making a screenshot?

Dang, I used to know this. :-( But I jut can't remember right now.

I suppose you've already searched the Cocoa-Dev archives for info on this? Also try Carbon-Dev. I know there used to be a way to get a port for the entire screen whose pixels you could query using CoreGraphics or Quickdraw.

I vaguely remember that the Cocoa way to do this had something to do with opening a full-screen transparent window, but I'm not sure whether that was only for getting the mouse tracking events, or whether that also allowed you to use NSReadPixel on that window's content view to get pixel values... (maybe you'll have to use NSView's PDF-data-generating method instead).

Also check out all those web sites in the "Cocoa and List Resources" post the admin does here every month or so. E.g. CocoaDev might contain some info on screen shots.

Cheers,
-- M. Uli Kusterer
http://www.zathras.de



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Pick color value from any pixel on screen
      • From: Shawn Erickson <email@hidden>
References: 
 >Pick color value from any pixel on screen (From: Cybereer <email@hidden>)
 >Re: Pick color value from any pixel on screen (From: Uli Kusterer <email@hidden>)

  • Prev by Date: NSPopupButtonCell handling click too early ? (Binding problem)
  • Next by Date: Re: [NSApp mainMenu] returns nil under 10.4.3
  • Previous by thread: Re: Pick color value from any pixel on screen
  • Next by thread: Re: Pick color value from any pixel on screen
  • Index(es):
    • Date
    • Thread