径向渐变绘制性能 - OpenGL-ES可以改进吗? [英] Radial gradient draw performance - Can OpenGL-ES improve?

查看:102
本文介绍了径向渐变绘制性能 - OpenGL-ES可以改进吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个图像处理应用程序,它覆盖从照片库加载的图像上的径向渐变。

I'm working on a image manipulation app that overlays a radial gradient over an image loaded from the photo library.

在屏幕上我有一个动态的滑块/减小径向渐变的半径。我发现模拟器上的性能还不错,但是在iPhone 3G或3GS上,移动滑块时重绘的速度要慢得多。

On screen I have a slider to dynamically in/decrease the radius of the radial gradient. I've found the performance on the simulator to be just fine, but on an iPhone 3G or 3GS it is much slower to redraw when moving the slider.

我目前正在使用 CGContextDrawRadialGradient 进行绘图。我每次重绘的步骤如下:

I'm currently using CGContextDrawRadialGradient for drawing. The steps I'm following for every redraw:


  1. 创建图形上下文: UIGraphicsBeginImageContext(size);

  2. 创建渐变对象: CGGradientCreateWithColorComponents

  3. 绘制图像(照片从照片库加载到屏幕比例: drawInRect

  4. 设置为叠加混合模式: CGContextSetBlendMode

  5. 绘制渐变: CGContextDrawRadialGradient

  6. 创建一个UIimage来自使用UIGraphicsGetImageFromCurrentImageContext();

  7. UIGraphicsEndImageContext();

  8. 绘制完整的图像屏幕: drawInRect

  1. Create the graphics context: UIGraphicsBeginImageContext(size);
  2. Create gradient object: CGGradientCreateWithColorComponents
  3. Draw the image (photo loaded from photo library) to the scale of the screen: drawInRect
  4. Set to an overlay blend mode: CGContextSetBlendMode
  5. Draw the gradient: CGContextDrawRadialGradient
  6. Create a UIimage from using UIGraphicsGetImageFromCurrentImageContext();
  7. UIGraphicsEndImageContext();
  8. Draw the completed image to screen: drawInRect.

是否有更快的绘制方式?也许使用OpenGL?

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

任何建议/示例代码都将受到赞赏。

Any suggestions/sample code would be appreciated.

谢谢。

推荐答案

以下是一些可能提高性能的想法

(假设您使用渐变为图像添加渐晕) :

Here are some ideas that might improve performance
(assuming you're using the gradient to add vignetting to the image):


  • CGLayer 中缓存图像绘制与视图大小相同,每次需要绘制时都会缩小

  • 缓存径向渐变的绘图进入另一个 CGLayer

  • 需要显示结果时

    • 绘制图像图层

    • 后跟叠加混合设置

    • 后跟渐变图层

    • 全部进入视图的绘图上下文。

    • cache your image drawing in a CGLayer that has the same size as the view, this avoids scaling each time you need to draw it.
    • cache the drawing of the radial gradient into another CGLayer.
    • when you need to show the result:
      • draw the image layer
      • followed by the overlay blend setting
      • followed by the gradient layer
      • all into the drawing context of the view.

      • 重绘渐变图层然后是合成。

      • 重绘合成,同时缩放渐变图层,当使用时将手指抬离滑块重绘渐变然后再次复合。

      • redraw the gradient layer then the composition.
      • redraw the composition while scaling the gradient layer, and when the use lifts his finger off the slider redraw the gradient layer then composite again.

      这篇关于径向渐变绘制性能 - OpenGL-ES可以改进吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆