开发者

CGContextSetShadowWithColor problem

Please look at the code first:

  UIGraphicsBeginImageContext(self.view.frame.size);
  contextRef=UIGraphicsGetCurrentContext();
  CGContextSetLineCap(contextRef, kCGLineCapRound);
  CGContextSetLineWidth(contextRef, brushWidth);
  CGContextSetRGBStrokeColor(contextRef, 1.0, 1.0, 1.0, 1.0);    

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  CGColorRef glowColor = CGColorCreate( colorSpace, colorValues );
  CGContextSetShadowWithColor( contextRef,CGSizeMake( 0.0, 0.0 ), 100.0f, glowColor );
  //CGContextSetShadow(contextRef, CGSizeMake(0.0, 0.0),100.0f);
  CGContextBeginPath(contextRef);

  while (beginY<ensdY) {
      //brushWidth=brushWidth-.05;
      CGContextMoveToPoint(contextRef, beginX, beginY);
      CGContextAddLineToPoint(contextRef,nextX,nextY);

      beginX=nextX;beginY=nextY;
      nextY=nextY+10;
      if (arc4random()%3==0) {
          nextX=nextX+arc4random()%10;
      } 
      else {
          nextX=nextX-arc4random()%10;
      }
  }

  CGContextStrokePath(contextRef);
  drawImage.image  = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

This code is called on a regular basis.

Everything is ok in simulator, but when I installed it onto the iPhone i开发者_StackOverflowt becomes slow. I find that this is for CGContextSetShadowWithColor, but don't know why.


this is a stab in the dark - but maybe try CGColorRelease(glowColor);


I tested CGContextSetShadowWithColor and it indeed becomes very slow with blur value of 50. Your blur value is 100, which is likely producing the slowdown effect.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜