我正在使用 CGContext 在 UIImageView 上徒手绘制线条。但是当我使用
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
图像是在 Imageview 中使用 imageView 的大小绘制的,因此原始图像的大小会调整为 imageView 的大小。我必须再次将图像大小调整为原始大小,同时这样做会失去质量。如何直接在 image 而不是 imageView 上绘制?此外,我必须使用 imageview 使图像适合 View ,以便我可以在其上画线。请帮助!!!
最佳答案
您可以重新渲染带有线条的图像
- (UIImage *)renderImage:(UIImage *)image atSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0.0, 0.0, size.width, size.height)];
//Draw your lines here
UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
虽然这可能不是最好的方法,但这取决于您对应用程序的处理方式。 希望这对您有所帮助。
关于iphone - CGContext绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12601450/