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. 在另一个图像(jQuery)的表面上绘制图像
- 4. 在一个UIImageView中绘制一个UIImage在另一个UIImageView内
- 5. 将从一个图像获得的轮廓绘制在另一个图像上
- 6. 在UIImage上绘图
- 7. 如何在另一幅图像上绘制图像?
- 8. PHP:如何在另一幅图像上绘制图像?
- 9. 在图像上绘制一个矩形
- 10. iPhone SDK - 如何绘制UIImage到另一个UIImage?
- 11. 在另一个上绘制缓冲图像?
- 12. Android:在另一个图像的中心绘制图像
- 13. 在Android中绘制漂浮在另一个图像上的图像
- 14. 如何在PDF中查找图像并在其上绘制另一个图像
- 15. Android:在另一个位图上绘制多个位图
- 16. 在绘图区域上绘制图像
- 17. 在另一个角落绘制图形
- 18. 在win32上绘制图像?
- 19. 在图像上绘制
- 20. 在图像上绘制点
- 21. 在Android上绘制多个图像
- 22. 在另一个图形上绘制链接和图形
- 23. 设置一个UIimage视图等于另一个UIimage视图
- 24. 什么是在另一幅图像上绘制图像的最快方式?
- 25. 将图像上下文绘制到已经缩放到另一个尺寸的UIImage中时位置不正确;
- 26. 在重叠面板上绘制图形,一个面板绘制固定和另一个绘制可移动
- 27. 在UIImage视图中绘制多段线图像
- 28. 让视图在另一个视图中控制UIImage
- 29. 我想在angular2上的图像上绘制一个矩形
- 30. 在UIImage上绘制一个透明的圆 - iPhone SDK
谢谢你,伙计,这是一个非常有用的片段。 –
这个效果很好,谢谢。不过,我建议你使用'UIGraphicsBeginImageContextWithOptions(size,false,0)'。这将为您提供屏幕正确分辨率的图像。 (默认情况下只会生成一张x1图像,这几乎肯定会模糊。) – Womble