3

I generate bitmap images with Cocoa using NSImage or CGImage (UIImage would work similar probably)

How do I determine what would be the maximum image size I can generate?

I guess it should be in some relation to the memory available?

MartinW
  • 4,966
  • 2
  • 24
  • 60
  • You cannot rely on the amount of free memory reported by a system. The problem is that the bitmap requires a **continuous** memory block of the necessary size. For example, you may need to allocate 100MB, a system reports that it has 500MB, but the memory may be too fragmented (i.e. consist of multiple pieces of, say, 50MB and smaller). In this case, it should throw "out of memory". In theory, this issue should not exist in 64-bit systems at all (at least on Windows), but... it is Apple after all. :-) – Andrew Simontsev Nov 16 '17 at 08:08
  • You might like to see a recent comment on an old post (Sep 15): https://stackoverflow.com/questions/12031704/image-size-for-uiimages-1024-x-1024 – mikep Nov 19 '17 at 11:42

1 Answers1

1

Apart from a tech curiosity, is always bad to allocate big images. Apple (especially for iPhone/iOS) has worked hard to use tiles and "tiled" classes (i.e. CATiledLayer) to display very large images. I saw it directly at WWDC in past years (see sample code PhotoScroller, https://developer.apple.com/library/content/samplecode/PhotoScroller/Introduction/Intro.html)

ingconti
  • 10,876
  • 3
  • 61
  • 48
  • Does the same apply not for displaying, but for creating images? – MartinW Nov 19 '17 at 17:07
  • good point! :) I will say: a) if not for displaying, you are processing images, try a file based solution b) iOS not the right solution. – ingconti Nov 20 '17 at 07:00