Tile an NSImage Within an NSBezierPath
Another snippet I had to write during the great Slider rebuild.
I needed to be able to take an NSImage supplied by the user and tile it within an NSBezierPath defined by more user-set values.
The below example uses a rounded rectangle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | NSBitmapImageRep *theImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:theImage]]; //bgImage can be any NSImage NSColor *c = [NSColor colorWithPatternImage:bgImage]; [c set]; [path appendBezierPathWithRoundedRect:NSMakeRect(0, 0, imageSize.width, imageSize.height) xRadius:10.0 yRadius:10.0]; [path fill]; [NSGraphicsContext restoreGraphicsState]; |
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Fill a Path With A Scaled Image, Ignoring Image Proportions
While continuing to rebuild Slider’s background image features, I was forced to rewrite the code that scales an image up/down to Slider’s portal size, ignoring the image’s original proportions. The image also had to be painted within a path, as Slider may have differently shaped corners compared to the image to be scaled.
The below code accomplishes the scaling and painting of the image.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //theImage = the resulting image, that will have a scaled (proportions ignored) version of "bgImage" painted onto it NSBitmapImageRep *theImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:theImage]]; NSImage bg = [[NSImage alloc] initWithSize: imageSize]; //bgImage can be any NSImage NSSize originalSize = [bgImage size]; [bg lockFocus]; [bgImage drawInRect: NSMakeRect(0, 0, imageSize.width, imageSize.height) fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height) operation: NSCompositeSourceOver fraction: 1.0]; [bg unlockFocus]; NSColor *c = [NSColor colorWithPatternImage:bg]; [c set]; [path appendBezierPathWithRoundedRect:NSMakeRect(0, 0, imageSize.width, imageSize.height) xRadius:10.0 yRadius:10.0]; [aPath fill]; [NSGraphicsContext restoreGraphicsState]; |
“path” could be any NSBezierPath.
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Fancy Footer Update
I’ve updated the Fancy Footer snippet, now Trackbacks/Pingbacks will be able to find your posts – the previous version’s implementation was … lacking.
The previous snippet used the post permalink as both the permalink and the path – the Trackback/Pingback system didn’t like “http://“ being included in the path attribute.
I was afraid that I wouldn’t be able to find a solution that allowed us to have Trackback/Pingback support and keep our existing comments.
I am glad to say that my fears were unfounded, and I managed to come up with a solution. The snippet now parses out the “http://domain.com” part of the permalink, and uses that for the path attribute for the widgets. Happily, JS-Kit must do a similar thing, as it hasn’t messed up my comments (the path attribute is what JS-Kit uses to determine what page to display which comments).
The snippet may be downloaded here. To learn how to use this snippet, read Fancy Footer – Usage and Tips.
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Archive Annihilator Improved Again
The solution for the ’sidebar explosion’ effect that the Archive Annihilator caused occurred to me earlier today. The fix was pretty simple, the fact that I didn’t think of it right away is a little embarrassing.
The update has been uploaded, and is available here.
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title



























Recent Comments
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
I would like to find any site to make permalink with my site,but I can't find one site.oh my god,who can help me?my site is http://www.shuangxi-hk.com
Tue, 18 May 2010 18:25:40 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http://store.taobao.com/shop/view_shop.htm?asker=wangwang&shop_nick=a333b444
http://item.taobao.com/auction/item_detail-0db2-40a79e949a57400b6b96edd149670677.htm
http://item.taobao.com/auction/item_detail-0db2-1d66cafb681edb96c634b894d2b1df3f.htm
http://item.taobao.com/auction/item_detail-0db2-a37ac99a003784d0c9b38150416d4c58.htm
http://item.taobao.com/auction/item_detail-0db2-f84bf08e8c573335b7d7ffe73a9d611b.htm
http://item.taobao.com/auction/item_detail-0db2-61c03a65b354488484ea0ec3076785b2.htm
http://item.taobao.com/auction/item_detail-0db2-e61b6c352c15689ee7eeca843f5345da.htm
http://item.taobao.com/auction/item_detail-0db2-958a432e957ab5c9e9b4fd6326a6ff55.htm
http://item.taobao.com/auction/item_detail-0db2-1d66cafb681edb96c634b894d2b1df3f.htm
http://item.taobao.com/auction/item_detail-0db2-484419d0d030152d16dd9dd2039c94c2.htm
http://item.taobao.com/auction/item_detail-0db2-43831f4a2dc611bccd1024ca3cf2b5f9.htm
http://item.taobao.com/auction/item_detail.htm?item_num_id=4955248190
http://item.taobao.com/auction/item_detail.htm?item_num_id=4957300818
http://item.taobao.com/auction/item_detail.htm?item_num_id=4957109628
Tue, 11 May 2010 15:02:41 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http://a333b444.taobao.com
Tue, 11 May 2010 14:55:51 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
GOOD
Tue, 11 May 2010 14:46:49 +0000
Installing Jdownloader In Ubuntu
Very nice tutorial, works like charm, ty very much
cheers!
Fri, 02 Apr 2010 10:58:11 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http:www.qq8080.com.cn
Fri, 02 Apr 2010 06:49:22 +0000