将CGPoint从CGRect转换为其他CGRect

我在视图上放置了一个标签,视图的框架是CGRectMake(0,0,270,203) 。 现在我必须用CGRectMake(0,800,600)进行屏幕截图。 所以我必须将标签从旧矩形转换为新矩形

这里是我用来拍摄的代码:

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]; 

但是我不能从新形象的标签中获得实际的位置。 任何人都可以帮助我哪里错了。

在这里,我已经附加了图像以获得更多解释。 在小视图中,我添加了一个标签,我必须根据大图像视图转换标签的框架。

将此视图中的标签转换为大视图。

在这里输入图像说明

谢谢,

  +(UIImage*)screenShotOf:(UIView*)view atScale:(CGFloat)scale { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, scale); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } 

这里您需要根据需要调整比例属性。

你可以做这样的事情:

 -(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 }; }