Re: floating point grayscale image?
Re: floating point grayscale image?
- Subject: Re: floating point grayscale image?
- From: Dan Waylonis <email@hidden>
- Date: Mon, 3 Dec 2001 19:27:26 -0800
On Sunday, December 2, 2001, at 10:29 AM, Roberto Abraham wrote:
>
I'm trying to create an image (directly in memory, i.e. I'm not
>
reading it
>
from a file) and display it as a grayscale intensity map. Each
>
pixel is a
>
floating point number. I'm afraid I'm hoplessly new to both
>
Cocoa and to
>
Objective-C programming and am having some trouble figuring out
>
how best
>
to go about displaying my data once I've created it in memory. [...]
Hi Roberto,
You can convert things to an NSBitmapImageRep, but you might be
best off using the CoreGraphics calls. They're very fast and
powerful. There really isn't too much documentation, but you
can look at the CG header files (which contain documentation) in:
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.
framework/Headers/*
Overview
You want to make a custom view, create a CGImage with a
CGDataProvider pointing at a function that converts your FP data
into whatever format you chose for your CGImage, and override
drawRect: to draw the CGImage in the view.
Details
Use CGDataProviderCreate() with your callbacks to function to
convert from FP to raster data.
Use CGColorSpaceCreateDeviceRGB();
Use CGImageCreate(); The CGImage can be whatever format you'd
like, but 32 bit ARGB or (xRGB -- no alpha) is the fastest,
native format.
In your custom view class, override the standard drawRect routine:
- (void)drawRect:(NSRect)rect
{
CGContextRef context = [[NSGraphicsContext currentContext]
graphicsPort];
CGContextDrawImage(context, rect, image);
}
Hopefully this will get you started!
Dan
__________________________________________________________________
Dan Waylonis email@hidden
Applications Engineering
http://waylda2.apple.com
Apple Computer, Inc. 408.974.0945 (O)
IL1, R318, MS 301-3KG 650.533.5333 (M)