Answer the question
In order to leave comments, you need to log in
How to merge UIImage's quickly?
+ (UIImage *)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage {
UIImage *image = nil;
CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height));
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(newImageSize);
}
[firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2),
roundf((newImageSize.height-firstImage.size.height)/2))];
[secondImage drawAtPoint:CGPointMake(roundf((newImageSize.width-secondImage.size.width)/2),
roundf((newImageSize.height-secondImage.size.height)/2))];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Answer the question
In order to leave comments, you need to log in
// Переходим в рабочий поток.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Выполняем мерджинг.
UIImage *resultImage = [UIImage imageByCombiningImage:firstImage withImage:secondImage];
// Возвращаем картинку в главный поток.
dispatch_sync(dispatch_get_main_queue(), ^{
imageView.image = resultImage;
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question