Drawing image with CoreGraphics on Retina iPad is slow

微笑、不失礼 提交于 2019-11-28 09:16:41

It looks like CoreGraphics is internally doubling the pixels, and then sending that to the GPU,

Pretty much. More accurately (in spirit at least):

  1. UIKit makes a CGBitmapContext the size of your view's bounds, in device pixels
  2. It makes that context the current context
  3. You draw your CGImage into that context
  4. ... so CG has to rescale the source image, and touch all of the destination pixels
  5. After you're done drawing, UIKit makes a CGImage from the bitmap context
  6. and assigns it to the view's layer's contents.

the CGImage that I'm making should be fine for passing to the GPU directly.

If you want that to happen, you need to tell the system to do that, by cutting out some of the steps above.

(There is no link between UIKit, CoreAnimation, and CoreGraphics that provides a "fast path" like you are expecting.)

The easiest way would be to make a UIImageView, and set its image to a UIImage wrapping your CGImageRef.

Or, set your view.layer.contents to your CGImageRef. (And make sure to not override -drawRect:, not call -setNeedsDisplay, and make sure contentMode is not UIViewContentModeRedraw. Easier to just use UIImageView.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!