19
A
回答
36
你可以一个子视图添加到您的UIImageView
包含与小实心三角形另一个图像。或者你可以绘制的第一个图像内:
CGFloat width, height;
UIImage *inputImage; // input image to be composited over new image as example
// create a new bitmap image context at the device resolution (retina/non-retina)
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), YES, 0.0);
// get context
CGContextRef context = UIGraphicsGetCurrentContext();
// push context to make it current
// (need to do this manually because we are not drawing in a UIView)
UIGraphicsPushContext(context);
// drawing code comes here- look at CGContext reference
// for available operations
// this example draws the inputImage into the context
[inputImage drawInRect:CGRectMake(0, 0, width, height)];
// pop context
UIGraphicsPopContext();
// get a UIImage from the image context- enjoy!!!
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
// clean up drawing environment
UIGraphicsEndImageContext();
此代码(source here)将创建一个新UIImage
,你可以用它来初始化一个UIImageView
。
20
你可以试试这个,完美的作品对我来说,这是UIImage的类别:
- (UIImage *)drawImage:(UIImage *)inputImage inRect:(CGRect)frame {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
[self drawInRect:CGRectMake(0.0, 0.0, self.size.width, self.size.height)];
[inputImage drawInRect:frame];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
或斯威夫特:
extension UIImage {
func image(byDrawingImage image: UIImage, inRect rect: CGRect) -> UIImage! {
UIGraphicsBeginImageContext(size)
draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
image.draw(in: rect)
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return result
}
}
相关问题
- 1. 我如何绘制一个图像到另一个UIImage来创建一个UIImage
- 2. 在UIView上快速绘制UIImage图像
- 3. opencv在另一个图像上绘制透明图像
- 4. 在另一个图像(jQuery)的表面上绘制图像
- 5. 在一个UIImageView中绘制一个UIImage在另一个UIImageView内
- 6. 将从一个图像获得的轮廓绘制在另一个图像上
- 7. 在UIImage上绘图
- 8. 如何在另一幅图像上绘制图像?
- 9. PHP:如何在另一幅图像上绘制图像?
- 10. 在图像上绘制一个矩形
- 11. iPhone SDK - 如何绘制UIImage到另一个UIImage?
- 12. 在另一个上绘制缓冲图像?
- 13. 在一个图上绘制2个阵列与另一个图
- 14. 在html5画布下的另一个图像下绘制图像
- 15. Android:在另一个图像的中心绘制图像
- 16. 在imagemagick中将图像绘制到另一个图像中?
- 17. 如何在PDF中查找图像并在其上绘制另一个图像
- 18. 在Android中绘制漂浮在另一个图像上的图像
- 19. UIImage drawinrect方法不绘制图像
- 20. Android:在另一个位图上绘制多个位图
- 21. 在绘图区域上绘制图像
- 22. opencv在一个图像上覆盖另一个图像,用蒙版和在图中绘制
- 23. 在另一个CWnd上绘制CWnd
- 24. 在另一个角落绘制图形
- 25. 在图像上绘制
- 26. 在win32上绘制图像?
- 27. 在图像上绘制点
- 28. Android - 在图像上绘制
- 29. 在JButton上绘制图像?
- 30. Android在另一幅图像中绘制图像
谢谢你,伙计,这是一个非常有用的片段。 –
这个效果很好,谢谢。不过,我建议你使用'UIGraphicsBeginImageContextWithOptions(size,false,0)'。这将为您提供屏幕正确分辨率的图像。 (默认情况下只会生成一张x1图像,这几乎肯定会模糊。) – Womble