UIImage with large image size - memory issue - crash

I wanted to download and display a large image (.jpg, .png), for example. 1800x1200 or 2000x1800 (width x height). If such large images (1800x1200 or 2000x1800) are displayed in the UIImageView, they also consume a lot of memory, and the application becomes crashed. Also, according to Apple's documentation ( http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html ), we should avoid creating UIImage objects larger than 1024 x 1024 in size. One solution is image resizing. I applied logic to resize the image using the following code.

UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

This works great and resizes the image. But when it loads a large image into the device context for resizing, it consumes a lot of memory for a second, and because of this, the application crashes. Therefore, this approach does not work. Please share if you have a better approach to resizing without glitches.

Also at this ( http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html ) Apple stated that

" UIImage 1024 x 1024. , , OpenGL ES . , , , 1024 x 1024 , . , ( ), ".

- "This size restriction does not apply if you are performing code-based manipulations, such as resizing an image larger than 1024 x 1024 pixels by drawing it to a bitmap-backed graphics context."? ? ? , - . !

+3
2

UIGraphicsBeginImageContext() ( CGBitmapContextCreate).

"" - , UIViews CALayers, CALayers , (, -, 2044 iPhone 2G/3G , , iPod Touch 1G/2G). 3GS , -, , .

, ; , (, ?).

+4

, , .

, , , , ( ). .

, CATiledLayer . WWDC'10 . .

+1

Source: https://habr.com/ru/post/1758746/


All Articles