Przechwyć UIView jako UIImage
Używam tej metody do Konwersji UIView
na UIImage
. tzn. screen snapshot of a view -
@interface UIView(Extended)
- (UIImage *) imageByRenderingView;
@end
@implementation UIView(Extended)
- (UIImage *)imageByRenderingView
{
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
@end
Aby go użyć, robię to -
UIImage *currImage = [self.view imageByRenderingView];
Daje to obrazową reprezentację całego UIView
. Teraz chcę 2 obrazy, jeden jest z górnej połowy UIView
, a drugi jest z dolnej połowy. Jak mam to zrobić?
19
Author: Srikar Appalaraju, 2011-08-24
1 answers
Możesz podzielić UIImage
na dwie części używając tego kodu:
CGImageRef topOfImageCG =
CGImageCreateWithImageInRect(currImage.CGImage,
CGRectMake(0,
0,
currImage.size.width,
currImage.size.height / 2.0));
UIImage *topOfImage = [UIImage imageWithCGImage:topOfImageCG];
CGImageRelease(topOfImageCG);
11
Author: pgb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-08-24 16:01:17
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-08-24 16:01:17