Re: Getting colour data at specified point in an NSImage
Re: Getting colour data at specified point in an NSImage
- Subject: Re: Getting colour data at specified point in an NSImage
- From: Michael Watson <email@hidden>
- Date: Thu, 15 Mar 2007 10:41:09 -0400
Yeah, I understand that no bitmap is drawn. I mentioned my drawing
concerns not because of that, but to illustrate why I was using
NSImage in the first place. The problem is that the memcopy during
the additional bitmap creation will hurt performance in my application.
What I've ended up doing is using an NSBitmapImageRep from the start,
instead of an NSImage, and then adding it as a representation to an
NSImage for drawing purposes later. This way, I can still access the
RGBA bytes directly via NSBitmapImageRep for my performance-sensitive
needs. Seems to work as I need.
--
m-s
On 15 Mar, 2007, at 08:33, email@hidden wrote:
Hi,
The code snippet draws no bitmap.
it just create a bitmap by capturing the contents of the locked image.
James
On Mar 15, 2007, at 1:15 AM, Michael Watson wrote:
Drawing the bitmap isn't really the problem. I'll be drawing into
the bitmap and then compositing several bitmaps into an NSImage.
Later, I'll need to scan bytes inside the bitmap data for some
information I want.
The only reason I'm using NSImage is because of -
drawInRect:fromRect:operation:fraction:, of which there is no
equivalent in NSBitmapImageRep. (I don't want to redraw entire
bitmaps, just sections of them.)
--
mikey
On 14 Mar, 2007, at 11:29, email@hidden wrote:
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:
40mac.com
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