Re: how to composite NSBezierPath and text on an image
Re: how to composite NSBezierPath and text on an image
- Subject: Re: how to composite NSBezierPath and text on an image
- From: Shawn Erickson <email@hidden>
- Date: Tue, 14 Sep 2004 08:58:28 -0700
Please do not cross post (posting to multiple mailing lists at once).
On Sep 13, 2004, at 9:34 PM, 김경옥 wrote:
Hi,
I'm trying to draw some BezierPath or text on an image in NSView and
save them as an image.
How can I save them into an image without bitmap data manipulation.
If the output destination is an NSView sub-class then in its drawRect:
method composite/draw your image then draw your paths and text over
that image. The docs for NSImage outlines the various composite/drawing
methods supported, etc.
If the end destination is a image file then either ask the NSView for
an image of itself ([1], [2], ...) or instead do your drawing into a
second NSImage instance that both your NSView can use for display and
you can use for saving to disk.
To draw into an NSImage instance simply create the instance then
lockFocus on it (or on a particular rep in the image), do your drawing,
then unlock focus.
[image lockFocus];
... draw stuff ...
[image unlockFocus];
When you go to save the image you can ask for various output formats
and compression settings by asking the bitmap image rep for a
particular image encoding using representationUsingType:properties:
(see the constants supported, for example NSJPEGFileType,
NSImageCompressionFactor, etc.). If you are working with an NSImage
instance then you will have to first ask that instance for the bitmap
image rep by either walking contained reps (representations) or asked
for the best one for a particular device
(bestRepresentationForDevice:).
And when I draw a BezierPath or text on a NSView, should
I reverse the y coordinate in drawing rect?
I don't understand the question... Why do you think this is need?
-Shawn
[1]
<file:///Developer/ADC Reference Library/documentation/Cocoa/
Reference/ApplicationKit/ObjC_classic/Classes/NSView.html#//apple_ref/
doc/uid/20000014/BBCHCCBC>
[2]
<file:///Developer/ADC Reference Library/documentation/Cocoa/
Reference/ApplicationKit/ObjC_classic/Classes/NSBitmapImageRep.html#//
apple_ref/doc/uid/20000347/initWithFocusedViewRectCOLON>
_______________________________________________
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