我在视图上放置了一个标签,视图的框架是CGRectMake(0,0,270,203).现在我要用CGRectMake(0,0,800,600).拍摄屏幕截图因此,我必须将标签从旧的转换为新的rect。
下面是我用来拍摄屏幕快照的代码:
CGRect rect = [view bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();下面是我用来转换点的代码:
CGRect f = [view convertRect:lblMessage.frame fromView:viewMessage];但我无法从新形象中的标签中获得实际的位置。有人能帮我找错地方吗。
在这里,我附上了图像,以获得更多的澄清。在小视图中,我添加了一个标签,我必须根据大图像视图转换标签的帧。


谢谢,
发布于 2014-05-05 06:14:11
+(UIImage*)screenShotOf:(UIView*)view atScale:(CGFloat)scale
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}这里,您需要根据需要调整缩放属性。
发布于 2014-06-13 20:32:17
你可以这样做:
-(CGPoint) convertPoint: (CGPoint) point fromRect: (CGRect) fromRect toRect: (CGRect) toRect {
return (CGPoint){
(toRect.size.width/fromRect.size.width) * point.x,
(toRect.size.height/fromRect.size.height) * point.y
};
}https://stackoverflow.com/questions/23465725
复制相似问题