ios uiimageview怎么获取坐标
1个回答
展开全部
// 在某个区域截图
- (UIImage*)grabImageWithRect:(CGRect)rect
{
CGFloat scale = self.scale;
CGRect rectTemp = CGRectMake(rect.origin.x*scale, rect.origin.y *scale, rect.size.width *scale, rect.size.height*scale);
CGImageRef subImageRef = CGImageCreateWithImageInRect(self.CGImage, rectTemp);
CGRect smallBounds = CGRectMake(0, 0, CGImageGetWidth(subImageRef), CGImageGetHeight(subImageRef));
// UIGraphicsBeginImageContext(smallBounds.size);
UIGraphicsBeginImageContextWithOptions(smallBounds.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, smallBounds, subImageRef);
UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
CFRelease(subImageRef);
UIGraphicsEndImageContext();
return smallImage;
}
你自己再额外写个方法 去计算那4个点所圈出来的区域~
// 在某个区域截图
- (UIImage*)grabImageWithRect:(CGRect)rect
{
CGFloat scale = self.scale;
CGRect rectTemp = CGRectMake(rect.origin.x*scale, rect.origin.y *scale, rect.size.width *scale, rect.size.height*scale);
CGImageRef subImageRef = CGImageCreateWithImageInRect(self.CGImage, rectTemp);
CGRect smallBounds = CGRectMake(0, 0, CGImageGetWidth(subImageRef), CGImageGetHeight(subImageRef));
// UIGraphicsBeginImageContext(smallBounds.size);
UIGraphicsBeginImageContextWithOptions(smallBounds.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, smallBounds, subImageRef);
UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
CFRelease(subImageRef);
UIGraphicsEndImageContext();
return smallImage;
}
你自己再额外写个方法 去计算那4个点所圈出来的区域~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询