是否可以向 UIImage/UIImageView 添加另一个更小的图像?如果是这样,如何?如果没有,那我怎么画一个小的实心三角形呢?
谢谢
最佳答案
您可以向您的 UIImageView
添加一个 subview ,其中包含另一个带有小实心三角形的图像。或者您可以在第一张图片的内部绘制:
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
。
关于iphone - 在 UIImage 上绘制另一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6656745/