• 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: Getting colour data at specified point in an NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting colour data at specified point in an NSImage


  • Subject: Re: Getting colour data at specified point in an NSImage
  • From: email@hidden
  • Date: Wed, 14 Mar 2007 23:29:20 +0800

Hi,
As matter of fact, you can't really lock focus on bitmap image representation.
lock focus on image will create a NSCachedImageRep which use offscreen window as drawing buffer.


If you would like to draw to the bitmap, you might have to use quartz's bitmap context
or something like this:
image = [[NSImage alloc] initWithSize:imageSize];
[image lockFocus];
[[NSColor colorWithCalibratedWhite:1.0 alpha:1.0] set];
NSRectFillUsingOperation(NSMakeRect(0, 0, imageSize.width, imageSize.height), NSCompositeCopy);
[[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(0, 0, imageSize.width, imageSize.height)];
[image unlockFocus];
[release];


But the second approach is much more in-efficient.(draw to offscreen window and then copy it to bitmap buffer)
HTH,
James


On Mar 14, 2007, at 6:32 AM, Michael Watson wrote:

Using NO for isPlanar has no effect, but yeah, later I'd be using planar data.

Either way, it's probably a good idea to use NO for testing purposes until I figure this out. :-)


-- mikey

On 13 Mar, 2007, at 18:25, Shawn Erickson wrote:

On 3/13/07, Michael Watson <email@hidden> wrote:
Oops, already spotted a mistake. This should be my initializer:

bitmapRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:imageSize.width
pixelsHigh:imageSize.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:YES
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0 // let NSBitmapImageRep take care of this
bitsPerPixel:32];

You are passing YES for isPlanar. Are you sure you really want a planar image?


Note sure if somehow that is causing you a problem.

-Shawn

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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)

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: Getting colour data at specified point in an NSImage
      • From: Michael Watson <email@hidden>
References: 
 >Getting colour data at specified point in an NSImage (From: Michael Watson <email@hidden>)
 >Re: Getting colour data at specified point in an NSImage (From: Michael Watson <email@hidden>)
 >Re: Getting colour data at specified point in an NSImage (From: Michael Watson <email@hidden>)

  • Prev by Date: [SOLVED]Re: Using math.h
  • Next by Date: Cocoa App distribution-related design and coding.
  • Previous by thread: Re: Getting colour data at specified point in an NSImage
  • Next by thread: Re: Getting colour data at specified point in an NSImage
  • Index(es):
    • Date
    • Thread