How can I improve CGContextFillRect and CGContextDrawImage performance

谁说我不能喝 提交于 2019-12-11 04:05:51

问题


Those two functions are currently my bottleneck. I am working with very large bitmaps.

How can I improve their performance?


回答1:


You could cache smaller versions of your bitmaps which you create before drawing the first time and then simply draw the downscaled samples instead of the full-blown 15 megapixel stuff.

Then again make sure you are only drawing what is necessary i.e. in 'drawRect: (NSRect) rect' only draw inside the rect (unless absolutely necessary). And try not do perform drawings outside of that method.




回答2:


If you're drawing large background images with content in the foreground that moves, consider using a layer-backed NSView, adding a layer and setting its background image. You can then draw your content in a other layers (or layer-backed NSViews) above the background layer, and the view will never need to redraw the background image because it is stored in the GPU's texture memory. Your current image is too large for a single CALayer (CALayers are limited to the maximum OpenGL texture size of 2048 x 2048) so you will probably need to break it up into tiles.

Otherwise, as @iolo mentioned, you should make sure that you only redraw the parts of the view that really need updating.



来源:https://stackoverflow.com/questions/6625654/how-can-i-improve-cgcontextfillrect-and-cgcontextdrawimage-performance

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