开发者

drawing NSImage tiles

开发者 https://www.devze.com 2022-12-14 17:48 出处:网络
how do i draw an NSImage into a view in a manner that it is tiled in a single line (there are no incomplete images drawn, and assuming that the image height is e开发者_StackOverflow中文版qual to the v

how do i draw an NSImage into a view in a manner that it is tiled in a single line (there are no incomplete images drawn, and assuming that the image height is e开发者_StackOverflow中文版qual to the view's height)?


If the image was the same size as the view, you wouldn't need to tile, so I don't quite understand.

However, take a look at NSDrawThreePartImage. On 10.6 you can pass nil for the caps if all you want is a single image tiled either horizontally or vertically.

The other option is to use something along the lines of

[[NSColor colorWithPatternImage:] set];
NSRectFill(rectToBeTiled);

but the phase and scale may not be what you want if you do it this way. Colors draw in what CG calls 'base space' which is kind of like drawing in the coordinate system of the window's content view. So basically, use NSDrawThreePartImage if you can.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号