Radial gradient increase effect - can OpenGL-ES improve?

I am working on an image processing application that applies a radial gradient to an image downloaded from a photo library.

On the screen, I have a slider for dynamically increasing / decreasing the radius of the radial gradient. I found that the performance on the simulator is very good, but on the iPhone 3G or 3GS it is much slower to redraw when moving the slider.

I am currently using CGContextDrawRadialGradient for drawing. The steps that I follow for each redraw:

  • Create a graphics context: UIGraphicsBeginImageContext(size) ;
  • Create Gradient Object: CGGradientCreateWithColorComponents
  • Draw an image (photo downloaded from the photo library) into the screen scale: drawInRect
  • Set the blend mode of the blend: CGContextSetBlendMode
  • Draw a gradient: CGContextDrawRadialGradient
  • Create a UIimage using UIGraphicsGetImageFromCurrentImageContext ();
  • UIGraphicsEndImageContext();
  • Draw the final image on the screen: drawInRect .

Is there a faster way to draw? Perhaps using OpenGL?

Any suggestions / code examples would be appreciated.

Thanks.

+7
ios iphone ios4 opengl-es
source share
1 answer

Here are some ideas that can improve performance.
(assuming you are using a gradient to add vignetting to the image):

  • cache your drawing image in CGLayer , which is the same size as the view, this avoids scaling every time you need to draw it.
  • snap a radial gradient drawing to another CGLayer .
  • when you should show the result :
    • draw an image layer
    • and then set up overlay overlay
    • followed by a gradient layer
    • all in the context of a drawing view.
  • when the user moves the slider , you can:
    • redraw the gradient layer , then the composition.
    • redraw the composition while scaling the gradient layer, and when use pushes the finger away from the slider, redraw the gradient layer, then draw it again.
+1
source share

All Articles