答案 0 :(得分:0)
考虑到您使用了三个图像视图。
IBOutlet UIImageView *lineView;
IBOutlet UIImageView *blackView;
IBOutlet UIImageView *redView;
您需要使用以下代码按照redView
的框架获取精确的裁剪图像。
UIGraphicsBeginImageContext(redView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect frame = lineView.frame;
frame.origin.x = lineView.frame.origin.x - redView.frame.origin.x ;
frame.origin.y = lineView.frame.origin.y - redView.frame.origin.y;
[redView.image drawInRect:redView.bounds];
[lineView.image drawInRect:frame];
CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
redView.image = img;
UIGraphicsEndImageContext();