Re: Converting an NSString to a series of NSImages?
Re: Converting an NSString to a series of NSImages?
- Subject: Re: Converting an NSString to a series of NSImages?
- From: Marco Binder <email@hidden>
- Date: Thu, 19 Sep 2002 12:55:03 +0200
Try the following:
- (void) makeImage:(NSString*) theString {
int i;
NSImage *stringImage;
// you create a new image with the text whih you will then put into an
NSImageView
stringImage = [[NSImage alloc] initWithSize:NSMakeSize([theString
length],32);
//Your image is going to be 32 pix high (if only one line) and 32*amout
of letters wide
[stringImage lockFocus];
// You r now drawing into the new image
for (i=0; i<[theString length]; i++) {
NSRect r = NSMakeRect(32*i,0,32,32);
[alphabetImage drawInRect:r
fromRect:getRectFor([theString characterAtIndex:i])
operation:NSCompositeCopy
fraction:1.0];
}
// Implement the function getRectFor:(unichar) to return the rect of
the appropriate
// letter from your alphabetImage (e.g. "A" => NSMakeRect(0,0,32,32);)
[stringImage unlockFocus];
[myImageView setImage:stringImage];
}
Never tested the code, but that s how I would try to do this kind of
stuff. As you can see, no miraculous function-calls, everything
straight from the developer documentation.
marco
Am Mittwoch, 18.09.02 um 20:06 Uhr schrieb Albert Atkinson:
Hello!
I am afraid I am stumped on this one, I can not find any documentation
on how to do this. I have an image file that contains a bunch of
letters, arranged like a sprite in rows of 10, each section is 32x32
pixels. What I would like to do is this, reference an NSString and
then print the appropriate letters into an NSImageView, basically
something like:
[myMethod makeImage: @"Hello!"];
Would select the appropriate letters from my NSImage and print them
into my NSImageView.
I have seen this done before (for example in the game TuxRacer,
probably not a Cocoa app but maybe some similar methods) Can anyone
help or provide sample code or something?
If you would like a sample image of how my letters are set up in my
image let me know and I will email it to you, unfortunately the list
does not like attachments.
--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.