Re: Function to write to one pixel?
Re: Function to write to one pixel?
- Subject: Re: Function to write to one pixel?
- From: Shawn Erickson <email@hidden>
- Date: Fri, 6 May 2005 17:21:13 -0700
On May 6, 2005, at 4:34 PM, Dustin Robert Kick wrote:
How can you create, for example, a pattern of crosshatched pixels,
with nothing behind them in the other pixels (though this is
probably a different topic), this was one thing I was thinking of
doing with painting single pixels. ( Paint a pattern of
crosshatches over another picture so that both would show up ).
But in particular, I was trying to paint a single pixel in the
middle of concentric circles, and couldn't find the function, which
I found to be odd.
In Cocoa (and Quartz) you paint on a virtual canvas using stroked and/
or filled paths (NSBezierPath / CGPath), using glyphs (from fonts,
etc.), bitmaps (NSImage / CGImage), vector graphics (PDFs, etc),
etc.. Of course additional things can be used to paint with
(CGPattern, CGLayer) and some in conjunction with others (NSShadow /
CGContextSetShadow, CGShading, etc.).
The virtual canvas is a continuous mathematical space defined in
floating point units with 1.0 unit in x or y equal to 1 / 72 of an
inch. This virtual canvas is called user space and it will be mapped
to an output device as needed by Quartz itself (screen, printer, PDF,
etc.) with a unit in user space being scaled up or down as needed
(think of the canvas as being stretched like a big rubber sheet). So
no such thing as a pixel really exist in user space just mathematical
objects (paths, etc. ) or mathematically transformed bitmaps that get
rendered to an output device at an arbitrary resolution (color
corrected, etc. as well).
Anyway the following would fill a black point in user space and
result in a single pixel on _screen_ being filled (assuming the CTM
is the identity matrix and ignoring antialiasing/alpha effects that
may come into play).
// called from a drawRect: method on while a view/context is focused
[[NSColor black] set];
NSRectFill(NSMakeRect(0.0, 0.0, 1.0, 1.0));
The same can be done this way using a NSBezierPath...
// called from a drawRect: method on while a view/context is focused
NSBezierPath* path = [NSBezierPath bezierPath];
[path moveToPoint:NSMakePoint(0.0, 0.0)];
[path lineToPoint:NSMakePoint(1.0, 0.0)];
[path lineToPoint:NSMakePoint(1.0, 1.0)];
[path lineToPoint:NSMakePoint(0.0, 1.0)];
[path closePath]; or [path lineToPoint:NSMakePoint(0.0, 0.0)];
[[NSColor black] set];
[path fill];
In the long run it sounds like you would want to draw many of the
above into a focused NSImage (with clear background) and then
composite that NSImage over your other images.
Or use patterns or more advances paths to achieve what you want.
Also consider using capabilities of Core Image if working on Tiger
and you are attempting to do effects on images (could possibly define
the operations in Quartz Composer.app and use them from your Cocoa
application).
Always look under /Developer/Examples/ if you have the developer
tools installed for code examples that cover the framework, etc. you
are using.
-Shawn
_______________________________________________
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