2

My line of code:

UIColor *brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"Frame-1@2x.png"]];
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),brushPattern.CGColor);
Image pattern

url

Which does not draw like brush pattern whereas it fill pattern in UIView

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Undertaker
  • 39
  • 1
  • 7

1 Answers1

1

I have used the following code for the same

At ViewDidLoad or Where ever your going to start the assign this

 patternColor = [UIColor colorWithPatternImage:image] 

This will resolve your memory issues and below code willhelp you

UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]);

CGContextRef context = UIGraphicsGetCurrentContext();
[view.image drawInRect:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];

CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, 10);

CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), patternColor.CGColor);
CGContextSetBlendMode(context, kCGBlendModeNormal);

CGContextBeginPath(context);
CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Shashank Kulshrestha
  • 1,556
  • 17
  • 31
  • I used this line of code previously but not filled my exact pattern.I want pattern like following url: "http://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-snc6/225074_513694782028209_1761743512_n.jpg" Previous was just filled UIView not control Brush Flow so how to Controlling of brush flow and and filled pattern For More you can see Paint Gallery app for using of brush flow and patten. – Undertaker Mar 04 '13 at 09:00
  • ImagePattern Url :[link](http://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-snc6/225074_513694782028209_1761743512_n.jpg)\n Paint Gallery app :[link](https://itunes.apple.com/us/app/paint-gallery/id445258482?mt=8) – Undertaker Mar 04 '13 at 09:14
  • I used the same code and was able to do the same you can go through this link http://stackoverflow.com/questions/14053563/how-to-unerase-the-erased-uiimage – Shashank Kulshrestha Mar 04 '13 at 09:28
  • I am find in apple to drawin .You can also check it is good to Core Graphics Layer Drawing [link]https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_layers/dq_layers.html#//apple_ref/doc/uid/TP30001066-CH219-TPXREF101 – Undertaker Mar 04 '13 at 14:35