Re: Generating simple on-the-fly TIFF files
Re: Generating simple on-the-fly TIFF files
- Subject: Re: Generating simple on-the-fly TIFF files
- From: Ken Tozier <email@hidden>
- Date: Sun, 4 Jul 2004 22:57:47 -0400
Louis,
Thanks! Your step by step worked perfectly.
Ken
On Jul 4, 2004, at 4:47 PM, Louis C. Sacha wrote:
Hello...
1) Create an NSImage with the correct size using [[NSImage alloc]
initWithSize:NSMakeSize(width,height)]
2) Lock focus on the NSImage to allow drawing into it using [yourImage
lockFocus]
3) Set the correct color for your frame, for example [[NSColor
redColor] set]
4) Frame the image using the NSFrameRectWithWidth(NSRect aRect, float
frameWidth) function from AppKit, using the rect
NSMakeRect(0.0f,0.0f,width,height) as the rect.
5) Create an attributes dictionary for the text you want to add to the
image and a string containing your text, or an NSAttributedString
containing your text.
6) Assuming that the lines of text are relatively short compared to
the width of the image, or manually line wrapped, get the
textRect.size of the drawn text by using the sizeWithAttributes:
NSString method on your string, or the size NSAttributedString method
on your attributed string.
7) Calculate the position of the text rect
textRect.origin.x = (image.size.width - textRect.size.width) / 2.0f;
textRect.origin.y = (image.size.height - textRect.size.height) / 2.0f;
8) Draw the text in the rect using the drawInRect:withAttributes:
NSString method or the drawInRect: NSAttributedString method.
9) Unlock focus from the image using [yourImage unlockFocus]
The NSFrameRectWithWidth() function is documented in "Graphics" in the
"Functions" section of the AppKit reference documentation.
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/ObjC_classic/Functions/AppKitFunctions.html#//
apple_ref/doc/uid/20000695/BAJJABBF
The NSString and NSAttributedString methods for drawing text are
documented in the AppKit reference documentation, under "NSString
Additions" and "NSAttributedString Additions". You can also force the
strings to manually wrap if necessary by using a fixed width for the
textRect, although it makes calculating the "centered" vertical
position of the text rect more interesting.
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/ObjC_classic/Classes/NSStringAdditions.html#//
apple_ref/doc/uid/20000155
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/ObjC_classic/Classes/NSAttributedString.html#//
apple_ref/doc/uid/20000167
Hope that helps,
Louis
That sounds easy enough, but the main problem isn't the tiff
conversion, it's generating the images out of thin air.
Basically I want to create an image with a specified width and
height, frame it with a border in a specified color and write 3 to 4
lines of styled text centered in the box horizontally and vertically.
Any tips or links on how to do that?
Thanks,
Ken
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.