1

I have a very, very large UIView, which uses a CATiledLayer.

I need to render a lot of small images onto it.

These small images are stored in one large image (1024x1024). They may have transparency.

At the moment, I use CGImageCreateWithImageInRect on the large image to create CGImageRefs for each small image that I need.

Later, within drawRect, I call CGContextDrawImage(context, rect, smallImage); to display each of these small images, as required.

According to Instruments' Time Profiler, however, there's a very large bottleneck at CGContextDrawImage (274ms), and I wish to reduce that as best I can (short of using OpenGL).

My question is: how? Is there an alternative to CGContextDrawImage which does not require scaling? Is using CGImageCreateWithImageInRect the right way to go about it?

9
  • Few questions - how big is the 'one large image'? are you using [UIImage imageNamed:@"yourImage"]? And also is your subclass overriding the 'layerClass' class method? Finally you should check this link out: cimgf.com/2011/03/01/subduing-catiledlayer Commented Jan 15, 2014 at 10:43
  • Can you please provide some clarification on what you are trying to achieve with the pattern you are following? You can have all the images cropped and added to the project before hand, which will reduce the time. Commented Jan 15, 2014 at 11:08
  • @Neuronical the one large image is 1024x1024. In OpenGL, it would be the texture I would use to blit all the little images, which are typically around 32 pixels in width and height. Yes, for my really big UIView, I am overriding 'layerclass', returning [CATiledLayer class]. Thanks for the link, but I should point out that the big image is just an image map for the little images, which are distributed over the extremely large UIView and not tiled together. Commented Jan 15, 2014 at 11:30
  • @kamran imagine a project to draw a folder window in Finder, where the folder contains tens of thousands of files. Each file has a non-unique icon associated; if you were to paste the unique icons together, they would fit a bitmap of size 1024x1024. This is similar to what I'm doing. The CATiledLayer is the folder window. I need to blit the icons as efficiently as possible. CGContextDrawImage has been identified as slow by Instruments. So what's the solution? Hope that clarifies the problem. Commented Jan 15, 2014 at 11:36
  • yes, Thanks. Let me think about it. There are cocos2d methods that do this sort of thing, but I am not sure if they can be used directly in your project without having to create a cocos2d project base. Please take a look at this link raywenderlich.com/32045/…, spritehelper.org/app/SpriteHelper_API_Documentation/… . I will try to think of something and let you know. Commented Jan 15, 2014 at 11:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.