3

We're creating an iOS photo app. In doing this, we have to create dynamically sized images up to about 2500x1600px. Once this image has been created, we want to draw smaller images on top of the big one reasonably quickly.

The problem as we can see it is that it's impossible to get a context larger than the screen resolution. The call does not crash, but it returns a nil-context. How can such a seemingly simple task be achieved?

Secondly, once this context is created, what is the fastest way to draw a small image at a given position on top of the big one?

Edit:

We found the solution. CGBitmapContextCreate returns nil because the width and height parameters were set as floats, not ints. Sometimes the solution is right there in front of you, and you're too blind to see it. Hopefully this answer can help other people that somehow have the same problem.

Pedery
  • 3,632
  • 1
  • 27
  • 39
  • The limitation, I believe, is not screen size but memory. There's very good discussion of the problem of displaying images that are too large for memory in the WWDC 2010 videos (if that's what you're asking). – matt Dec 16 '11 at 04:47
  • Well, I don't think so. Even in our worst case, 2500x1600x4bpp=16MB, which is still within the limitations of the phone. In practice it will be a lot lower. The call returns a nil context, and that, of course, cannot be used for anything. If the bitmap context is reduced to the screen resolution, everything works. – Pedery Dec 16 '11 at 06:16
  • Awesome, Pedery. When you have a chance, please post that as an answer and accept it! – s4y Dec 17 '11 at 19:21
  • Actually, it was my colleague that was working on this problem and I just posted the question here for him. Since he figured it out himself, he now answered the question and it's been marked as accepted. Glad we found the solution :) – Pedery Dec 17 '11 at 23:36

2 Answers2

1

Make sure you specify integer widths and heights as the arguments to CGBitmapContextCreate, otherwise it returns nil. Otherwise, the size of the context should not matter as long as you can malloc enough memory for it.

oohaba
  • 592
  • 5
  • 17
0

It should be possible to get a context for almost any bitmap for which you can allocate/malloc enough memory, in your case multiples of 2500x1600x4 bytes of ARGB pixels.

You might also want to look into using a CATiledLayer, where you would only have to draw into the tiles covered by the smaller image. You may have to tile to support older devices which are limited by the max tile size that will fit into the GPUs texture cache.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153