(no subject)
(no subject)
- Subject: (no subject)
- From: spiderlama <email@hidden>
- Date: Sat, 23 Jun 2007 15:27:31 +1000
Hi, I am inexperienced with Cocoa, and so am having some troubles.
What I want to do is apply an image to the background of a window.
This (smaller) image will consist of a stretched (bigger) NSImage,
which is also masked. I wish to know how to create the mask and apply
it, as well as if this implementation is the most efficient.
I have the image being resized using this function (I don't know if
this is the best way to do it):
- (NSImage*)resizeImage: (NSImage*)image toSize:(NSSize)size {
NSImage *result = [[NSImage alloc] initWithSize: size];
[result lockFocus];
[[NSGraphicsContext currentContext] setImageInterpolation:
NSImageInterpolationHigh]; // smooths the image
[image drawInRect: NSMakeRect(0, 0, size.width, size.height)
fromRect: NSMakeRect(0, 0, [image size].width,
[image size].height)
operation: NSCompositeSourceOver
fraction: 1.f];
[result unlockFocus];
return result;
}
And then displaying it with:
[window setBackgroundColor: [NSColor colorWithPatternImage: image]];
[window display];
[image release];
Now I don't know how to build or apply the mask to this image. The
mask should consist of an end cap being resized (down) and then
placed on each end (the opposite end would have a horizontally
flipped version) and then between it filled with black (so the image
shows through).
Eg. the cap looks like:
+------------+
| white / |
| / |
| / |
| / black |
+------------+
And the full mask should look like (with the cap resized to
appripriate hight)
|<-- arbitrary width (changes) -->|
+------------+---------------------------------+------------+
| white / | | \ white |
| / | | \ |
| / | black | \ |
| / black | | black \ |
+------------+---------------------------------+------------+
I assume you would create another NSImage and draw the mask-cap to an
end, flip it and then draw to the other end, but I do not know how to
do this.
Your help is greatly appreciated.
Thanks,
Matt.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden