iphone - 在 UIImage 上绘制另一个图像

标签 iphone objective-c uiimageview uiimage drawing

是否可以向 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/

相关文章:

iphone - 如何在 tableviewrow 中查找或跟踪子点击(Titanium Studio)

ios - View Controller 没有填满屏幕 Xcode

objective-c - 在 Swift 中创建 NSDateFormatter?

ios - 将 UIImageView 从 subview 动画到父 View

iphone - NSTimer scheduleTimerWithTimeInterval 和 CoreAnimation

ios - imageview 图像填充适合模式

ios - XMPPFramework - 存在不变

iphone - 单击任何UIImage并在Objective-C中打开UIImageView

ios - 使用百分比揭示 UIImageView

iphone - 如何将包含毫秒数的大整数转换为 Min :Sec:Mili Objective-c