How to create a pattern with an image in a specific rectangle

  • I am trying to draw a pattern inside a particular rectangle drawn in my
    view.  The pattern is created from an NSImage .  I am currently
    creating the pattern using [NSColor colorWithPatternImage:myImage].
    This works for creating the pattern from the image, but I would like to
    draw the pattern inside of a specific rectangle in the view, and
    colorWithPatternImage always tiles the image starting from the bottom
    of the window.  I have seen this issue brought up in this list before,
    but I have not seen a solution presented yet for specifying your own
    origin other than the bottom of the window.  I would also like to apply
    scaling and rotation transforms to my pattern, but this also seems
    impossible to do when using colorWithPatternImage.  I have also looked
    at using Quartz to create and draw my pattern since it seems to do
    everything I would like with patterns, scaling, rotation, and cell
    spacing, but it appears to me that Quartz will only create patterns
    using solid colors.  If Quartz is my best bet for creating a pattern,
    does anyone know how I can create a Quartz pattern from an image?

    Thanks for any information.

    Derrick Griffel
    Intriguing Development Inc.
    816-229-6768 ext. 12
    www.idevelop.net
  • On Tue, 15 Mar 2005 09:04:30 -0600, Derrick Griffel <dgriffel...>
    said:
    > I am trying to draw a pattern inside a particular rectangle drawn in my
    > view.  The pattern is created from an NSImage .  I am currently
    > creating the pattern using [NSColor colorWithPatternImage:myImage].
    > This works for creating the pattern from the image, but I would like to
    > draw the pattern inside of a specific rectangle in the view, and
    > colorWithPatternImage always tiles the image starting from the bottom
    > of the window.  I have seen this issue brought up in this list before,
    > but I have not seen a solution presented yet for specifying your own
    > origin other than the bottom of the window.

    Draw the pattern color into a big rectangle in an offscreen image and then
    copy the desired rectangle of that into your visible rectangle. m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide
    <http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>