Re: NSImage -> 1-bit NSBitmapImageRep
Re: NSImage -> 1-bit NSBitmapImageRep
- Subject: Re: NSImage -> 1-bit NSBitmapImageRep
- From: Ricky Sharp <email@hidden>
- Date: Wed, 09 Feb 2005 07:52:31 -0600
On Tuesday, February 08, 2005, at 11:29PM, Sanford Selznick <email@hidden> wrote:
>I've got an NSImage with black and white data in it. I'd like to
>copy the black and white contents to a 1-bit-per-pixel
>NSBitmapImageRep.
>
>What's the best way to do this?
>
>I need 1-bit-per-pixel data, rowbytes and a rect so I can pass them
>into a library.
See the MonochromeImage sample code at Apple's site. It shows you how to work with an original NSImage and use its data to construct a monochrome image rep.
Note that you'll need to modify the parameters to initWithBitmapDataPlanes:pixelsWide... in order to specify 1 bpp.
Things to consider:
* The sample uses NSReadPixel which is very slow. What I've been doing is using "direct pixel access". i.e. I get a pointer into the source and destination data streams by using [someImageRep bitmapData].
* The original source rep may have alpha (hasAlpha returns YES) and may be planar (isPlanar returns YES). Your code should be modified to work with such data.
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
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