CGContextSetShadowWithColor Problem

Check out 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 regularly.

Everything is fine in the simulator, but when I installed it on the iPhone, it becomes slow. I find it for CGContextSetShadowWithColor, but I donโ€™t know why.

+3
source share
2 answers

it's a blow in the dark, but maybe try CGColorRelease (glowColor);

0
source

I tested CGContextSetShadowWithColor and it really gets really slow with a blurry value of 50. Your blur value is 100, which probably creates a slowdown effect.

0
source

Source: https://habr.com/ru/post/1754176/


All Articles