Re: Pictures as characters
Re: Pictures as characters
- Subject: Re: Pictures as characters
- From: Ryan Stevens <email@hidden>
- Date: Sat, 22 Jan 2005 08:07:01 -0800
On Jan 21, 2005, at 8:34 AM, Ricky Sharp wrote:
On Friday, January 21, 2005, at 08:20AM, Peter Karlsson
<email@hidden> wrote:
I have 32 NSImageView's in my app, located as a row. I take a 32
character
NSString and convert the first char to a ascii filename (for example A =
65.tif) and load a picture in the first NSImageView. The 32 NSImageView's
is called view1Outlet, view2Outlet and so on. This is a lot of work. Is
there another and better way to use pictures as characters?
What in the world are you trying to do here? What are the contents of
65.tif? Is it just a bitmapped version of the character 'A'?
On Friday, January 21, 2005, at 09:43AM, Peter Karlsson <email@hidden> wrote:
Yes, made in Photoshop.
Ok...I used to do this in the Carbon version of my app. I rendered all the glyphs I needed into a single 'tiled' image.
Rather than having 32 separate views, I'd suggest just making a single custom NSView. Or, if you need things a bit more general purpose, subclass NSCell, then create a matrix of 32 of those cells.
In terms of the tiled image, first choose a layout for your tiles. For example, you may want to have a very wide image (1 row of 32 tiles) or a very narrow image (1 column of 32 tiles). Or even n x m rows/columns. It's really up to you.
Let's say that you're doing the custom NSCell solution. Your cell could use its intValue to describe the index of the tile it should render (or perhaps you can add a separate attribute).
You'd then use NSImage's drawInRect:fromRect:operation:fraction to copy the appropriate rectangle of image data from your titled image.
For example, say your tiled image is 1 row and 32 columns. The indecies of the tiles would then be in the range [0..31] And, say that each tile is 64x64 pixels.
Given an index i, the rectangle to use for the 'fromRect' parameter would simply be:
NSRect theTileRect = NSMakeRect (i * 64, 0, 64, 64);
Or you could use the support for multiple representations...
image1, image2; // A, and B images
[image1 addRepresentation: [[image2 representations] objectAtIndex:0]]]; // add B to A.
...and so on. Then grab the TIFFRepresentation and writeToFile.
And once you've got it all in a single file you could use a category for easy access...
@implementation NSImage (Convenience)
- (NSImage *)imageFromRepAtIndex:(int)index
{
id rep = [[self representations] objectAtIndex:index]; // !sane
NSImage *tmp = [[NSImage alloc] initWithSize:[rep size]];
[tmp addRepresentation:rep];
return [tmp autorelease];
}
@end _______________________________________________
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