我使用CGContext在UIImageView中画手绘线。下面的代码:
UIGraphicsBeginImageContext(self.frame.size);CGContextRef context= UIGraphicsGetCurrentContext();
但是画在ImageView中,图的尺寸就变成了ImageView的大小,我还要在调整成原来的尺寸,调整之后图片就失真了。能不能跳过imageView直接在图中画?而且必须要imageView适应图片,这样能画线。帮帮忙~
你要在线条图的顶部重新渲染:
- (UIImage *)renderImage:(UIImage *)image atSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0.0, 0.0, size.width, size.height)];
UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
```swift
// 根据图片适配屏幕。不失真
UIGraphicsBeginImageContextWithOptions (self.bounds.size, false , UIScreen.main.scale)
```