I am new to iPhone app development, so I’m probably doing something wrong.
Basically, I download a bunch of images from the Internet and then crop them. I managed to find examples of loading images asynchronously and adding them to views. I was able to do this by adding an image with NSDatathrough NSOperationwhich was added to NSOperationQueue.
Then, since I had to make thumbs of a fixed size, I needed a way to crop these images, so I found a script on a network that mainly uses it UIGraphicsBeginImageContext(), UIGraphicsGetImageFromCurrentImageContext()and a UIGraphicsEndImageContext()cropped image for drawing, as well as unimportant size calculations , to draw.
The fact is that this method works, but since it generates 20 such images, it accidentally crashes after some of them have been generated, or sometimes after closing and reopening the application once or twice.
What to do in this case? I also tried to run these methods asynchronous, with NSOperationsand NSOperationQueue, but no luck.
If the lesson code is more appropriate than I think, here it is:
UIGraphicsBeginImageContext(CGSizeMake(50, 50));
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = CGPointMake(0.0,0.0);
thumbnailRect.size.width = 50;
thumbnailRect.size.height = 50;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
Thanks!
source
share