Re: Filling View With Pattern Image
thanks Florian. i'll be sure to use your helpful code for my mac programming. :) On Fri, Jun 19, 2009 at 4:27 AM, Florian Soenens wrote: > You will have to do it programmatically but it's pretty easy stuff. > This should do the trick nicely: > > -(void)drawBackgroundPattern > { > // Suppose backgroundPatternImage is a valid reference to your > pattern image > > NSRect rect = [self frame]; > > float width = rect.size.width; > float height = rect.size.height; > > float bgWidth = [backgroundPatternImage size].width; > float bgHeight = [backgroundPatternImage size].height; > float xPos = 0; > float yPos = height - bgHeight; > > while(yPos >= 0 - bgHeight) > { > while (xPos < width) > { > NSRect drawRect = NSMakeRect(xPos, yPos, bgWidth, > bgHeight); > [backgroundPatternImage drawInRect:drawRect > fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; > xPos += bgWidth; > } > xPos = 0; > yPos -= bgHeight; > } > } > > -(void)drawRect:(NSRect)aRect > { > [self drawBackgroundPattern]; > } > > hth, > Florian. > > On 19 Jun 2009, at 10:14, Chunk 1978 wrote: > >> i have this image ("image.png") that i would like to tile throughout >> the view... >> >> i've read the Quartz 2D programming guide... ok, ok, i breezed thru >> it, i admit... but i couldn't seem to find an easy way of repeating an >> image through out a view without actually drawing the image >> programatically... >> ___ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> 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: >> http://lists.apple.com/mailman/options/cocoa-dev/florian.soenens%40nss.be >> >> This email sent to florian.soen...@nss.be > > > > Looking for Web-to-Print Solutions? > Visit our website : http://www.vit2print.com > > > This e-mail, and any attachments thereto, is intended only for use by the > addressee(s) named herein and may contain legally privileged and/or > confidential information and/or information protected by intellectual > property rights. > If you are not the intended recipient, please note that any review, > dissemination, disclosure, alteration, printing, copying or transmission of > this e-mail and/or any file transmitted with it, is strictly prohibited and > may be unlawful. > If you have received this e-mail by mistake, please immediately notify the > sender and permanently delete the original as well as any copy of any e-mail > and any printout thereof. > We may monitor e-mail to and from our network. > > NSS nv Tieltstraat 167 8740 Pittem > Belgium___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/chunk1978%40gmail.com > > This email sent to chunk1...@gmail.com > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Filling View With Pattern Image
hi rob, thanks for this answer. i forgot to mention that it is for UIView on iPhone OS. i just found a super simple way of managing this using the backgroundColor property of the view: self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]; On Fri, Jun 19, 2009 at 4:24 AM, Rob Keniger wrote: > > On 19/06/2009, at 6:14 PM, Chunk 1978 wrote: > >> i have this image ("image.png") that i would like to tile throughout >> the view... >> >> i've read the Quartz 2D programming guide... ok, ok, i breezed thru >> it, i admit... but i couldn't seem to find an easy way of repeating an >> image through out a view without actually drawing the image >> programatically... > > > It's actually a little complicated, you need to create an NSColor instance > using a pattern image and then when you draw it you need to set the > patternPhase of the current NSGraphicsContext so that your image is drawn in > the correct place. > > Have a look at Dave Batton's excellent DBBackgroundView: > > http://www.mere-mortal-software.com/blog/details.php?d=2007-01-16&c=show > > -- > Rob Keniger > > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/chunk1978%40gmail.com > > This email sent to chunk1...@gmail.com > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Filling View With Pattern Image
You will have to do it programmatically but it's pretty easy stuff. This should do the trick nicely: -(void)drawBackgroundPattern { // Suppose backgroundPatternImage is a valid reference to your pattern image NSRect rect = [self frame]; float width = rect.size.width; float height = rect.size.height; float bgWidth = [backgroundPatternImage size].width; float bgHeight = [backgroundPatternImage size].height; float xPos = 0; float yPos = height - bgHeight; while(yPos >= 0 - bgHeight) { while (xPos < width) { NSRect drawRect = NSMakeRect(xPos, yPos, bgWidth, bgHeight); [backgroundPatternImage drawInRect:drawRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; xPos += bgWidth; } xPos = 0; yPos -= bgHeight; } } -(void)drawRect:(NSRect)aRect { [self drawBackgroundPattern]; } hth, Florian. On 19 Jun 2009, at 10:14, Chunk 1978 wrote: i have this image ("image.png") that i would like to tile throughout the view... i've read the Quartz 2D programming guide... ok, ok, i breezed thru it, i admit... but i couldn't seem to find an easy way of repeating an image through out a view without actually drawing the image programatically... ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/florian.soenens%40nss.be This email sent to florian.soen...@nss.be Looking for Web-to-Print Solutions? Visit our website : http://www.vit2print.com This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information and/or information protected by intellectual property rights. If you are not the intended recipient, please note that any review, dissemination, disclosure, alteration, printing, copying or transmission of this e-mail and/or any file transmitted with it, is strictly prohibited and may be unlawful. If you have received this e-mail by mistake, please immediately notify the sender and permanently delete the original as well as any copy of any e-mail and any printout thereof. We may monitor e-mail to and from our network. NSS nv Tieltstraat 167 8740 Pittem Belgium ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Filling View With Pattern Image
On 19/06/2009, at 6:14 PM, Chunk 1978 wrote: i have this image ("image.png") that i would like to tile throughout the view... i've read the Quartz 2D programming guide... ok, ok, i breezed thru it, i admit... but i couldn't seem to find an easy way of repeating an image through out a view without actually drawing the image programatically... It's actually a little complicated, you need to create an NSColor instance using a pattern image and then when you draw it you need to set the patternPhase of the current NSGraphicsContext so that your image is drawn in the correct place. Have a look at Dave Batton's excellent DBBackgroundView: http://www.mere-mortal-software.com/blog/details.php?d=2007-01-16&c=show -- Rob Keniger ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Filling View With Pattern Image
i have this image ("image.png") that i would like to tile throughout the view... i've read the Quartz 2D programming guide... ok, ok, i breezed thru it, i admit... but i couldn't seem to find an easy way of repeating an image through out a view without actually drawing the image programatically... ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com