NSImages rendered at runtime and resolution independent UI...
NSImages rendered at runtime and resolution independent UI...
- Subject: NSImages rendered at runtime and resolution independent UI...
- From: "Shawn Erickson" <email@hidden>
- Date: Fri, 27 Oct 2006 11:57:15 -0700
I am attempting to get my code ready for resolution independence and I
am trying understand the best way to deal with icon images that I
create at runtime. The below is a cut down example of icon image cache
generation code that I have (the simplest example I have and not one
that would visually benefit the most but...).
Ideally when the user interface scale factor is other then 1.0 I would
want to create an NSImage that is still 12 point by 12 point but has
its pixel content scaled (DPI other then 72) at the time it is created
by the user interface scale factor. I know the framework will scale it
as needed when I go to draw the image but I want to create the image
content at the resolution needed for display to avoid unneeded
interpolation and rep caching.
It isn't clear to me if the following drawing code will automatically
create an image 12 by 12 point image with pixel DPI already adjusted
as needed for screen display (avoiding unneeded interpolation) or
should I modify the code in some fashion to allow the creating of
image content at a higher DPI then 72?
If I need to do the later any recommendations on the best way to go
about doing this?
static NSImage* coloredPenIcons[12] = {nil};
if (coloredPenIcons[0] == nil) {
NSSize imageSize = NSMakeSize(12.0, 12.0); // size in points
NSBezierPath* penBody = [NSBezierPath bezierPath];
[penBody moveToPoint:NSMakePoint(1.0, 3.0)];
...
NSBezierPath* penShadow = [NSBezierPath bezierPath];
[penShadow moveToPoint:NSMakePoint(1.0, 2.0)];
...
NSAffineTransform* transform = [NSAffineTransform transform];
// Translate the origin to the center of the point grid, the
coordinate (0,0)
// is considered the lower left edge of a point in user coordinate space so
// translating by 0.5 will place our drawing centered in the point grid.
[transform translateXBy:0.5 yBy:0.5];
NSColor* shadowColor = [[NSColor colorWithCalibratedRed:COLOR256(150)
green:COLOR256(150)
blue:COLOR256(150)
alpha:1.0] set];
for (int i = 0; i < 12; i++) {
NSImage* image = [[NSImage alloc] initWithSize:imageSize];
[image lockFocus];
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
[transform concat];
[[NSColor colorWithCalibratedRed:COLOR256(150)
green:COLOR256(150)
blue:COLOR256(150)
alpha:1.0] set];
[penShadow stroke];
...color for pen body varies based on index...
[penBody fill];
[penBody stroke];
[image unlockFocus];
coloredPenIcons[i] = image;
}
}
-Shawn
_______________________________________________
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