Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Text drawing and exporting.

Text drawing and exporting.
Thread Tools
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Apr 28, 2002, 03:12 AM
 
OK, I am writing a quick app for personal use. It should generate a preview image (.gif) for use on a site.

This is what I am generating:



Now I have everything drawn, except the text with the black stroke. Now how can I do this? Someone told me to convert the text to a NSBezierLine and then add the stroke there? Or something... I am really a completely newbie so please be easy on me.


And secondly, I need to export the final thing to .GIF. Now In anticipiation of this, I put all my image views and text fields in 1 custom view. Now, how can I convert this custom view to a NSImage and then export it to a .GIF?

Thanks a lot, if you need the source, just ask!
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Apr 28, 2002, 10:34 AM
 
I can't really help you with the NSBezierPath issues right now (I haven't used them in some time) but I do know that you can save an image to a gif if you can get an NSBitmapImageRep from it. Using the NSBitmapImageRep you can then call:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> - (NSData *)representationUsingType NSBitmapImageFileType)storageType properties NSDictionary *)properties
</font>[/code]

with "NSGIFFileType" as the storageType and nil (I think) for properties. You will have to look into more of what the properties dictionary needs to be since I don't have my code with me right now where I did this.

Hope that is of some help,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Synotic  (op)
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Apr 29, 2002, 12:23 AM
 
Originally posted by Apocalypse:
<STRONG>I can't really help you with the NSBezierPath issues right now (I haven't used them in some time) but I do know that you can save an image to a gif if you can get an NSBitmapImageRep from it. Using the NSBitmapImageRep you can then call:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> - (NSData *)representationUsingType NSBitmapImageFileType)storageType properties NSDictionary *)properties</font>[/code]

with "NSGIFFileType" as the storageType and nil (I think) for properties. You will have to look into more of what the properties dictionary needs to be since I don't have my code with me right now where I did this.

Hope that is of some help,
Jeff.</STRONG>
[Yes, that definitely helps... So I am looking at something like:

[[myBitmapImageRep representationUsingType:NSGIFFileType, properties:nil] writeToFile:@"/users/synotic/preview.gif" atomically:YES ]

right?

Now here's what I come up with various help...

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>- (IBAction)generatePreview id)sender
{
NSImage *previewImage=[[NSImage alloc] init];

[imagewell2 setImage:[imagewell1 image]];
[previewdate setStringValue:[<font color = orange>@"Date: "</font> stringByAppendingString:[formdate stringValue]]];
[previewversion setStringValue:[<font color = orange>@"Version: "</font> stringByAppendingString:[formversion stringValue]]];
[previewsize setStringValue:[<font color = orange>@"Size: "</font> stringByAppendingString:[formsize stringValue]]];

[previewImage lockFocus];
[previewview drawRect:[previewview bounds]];
[previewImage unlockFocus];

[[[previewImage TIFFRepresentation] representationUsingType:NSGIFFileType properties:nil] writeToFile:<font color = orange>@"/Users/synotic/Desktop/previewimage.gif"</font> atomically:YES ];

}</font>[/code]

Now supposedly previewImage is supposed to become the custom view... but right when it tries to do the lockFocus.. I get a "Cannot cache image". Any other ideas how I can get the view to become an image?

Again, thanks!

[ 04-29-2002: Message edited by: Synotic ]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:14 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2