Re: Compositing text onto an NSImageView
Re: Compositing text onto an NSImageView
- Subject: Re: Compositing text onto an NSImageView
- From: John Hörnkvist <email@hidden>
- Date: Fri, 8 Jun 2001 12:43:07 +0200
On Friday, June 8, 2001, at 09:49 AM, Will Price wrote:
I have an NSImageView with an image in it. I now want to place text
overlayed on top of the image rotated at a 45 degree angle similar to
a watermark.
I'd do something like this:
@interface MyImageView:NSImageView
{
NSAttributedString* text;
}
- (void)drawRect:(NSRect)aRect;
@end
@implementation MyImageView
- (void)drawRect:(NSRect)aRect
{
[super drawRect:aRect];
[NSGraphicsContext saveGraphicsState];
{
NSAffineTransform* transform=[NSAffineTransform transform]; [transform rotateByDegrees:
45];
[transform concat];
NSClipRect(aRect);
// I think you may want to flip the view before drawing.
[text drawAtPoint:NSMakePoint(0,0)];
}
[NSGraphicsContext restoreGraphicsState];
}
@end
I wrote this in the letter, so it has never been compiled, and is
completely untested.
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com