I've created this method to resize an image.
+ (UIImage *)imageFromImage:(UIImage *)image scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
All works fine, but if I call this method in another thread it crashes at the drawInRect:
I use these lines to call this method in another thread:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (int i = 0; i < [images count]; i++){
UIImage *img = [UIImage imageWithContentsOfFile:[images objectAtIndex:i]];
CGFloat wImg = img.size.width * imageViewSize / img.size.height;
CGSize size = CGSizeMake(wImg, imageViewSize);
img = [Utility imageFromImage:img scaledToSize:size];
}
});
How can i do?