ios - 在另一个 uiimage 之上创建图像

标签 ios objective-c iphone ios7 cgcontext

我无法在另一张图片上绘制一张图片。下面是我正在使用的代码:

-(void)createImage
{

// create a new bitmap image context at the device resolution (retina/non-retina)
UIGraphicsBeginImageContextWithOptions(imgVw_noHair_.frame.size, 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
[eraser drawAtPoint:CGPointMake(50, 50)];

// pop context
UIGraphicsPopContext();

UIImage _image_ = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

}

我从当前上下文中得到的图像是黑色图像。我想在从上下文中获取的图像上绘制橡皮擦图像。

最佳答案

这是在我这边工作的更新代码。

-(void)createImage
{

   //Create context in which you have to draw
    UIGraphicsBeginImageContextWithOptions(imgvwImage.image.size, 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);

    //draw the old image in that context
    [imgvwImage.image drawInRect:CGRectMake(0, 0, 200, 200)];

    UIImage *img=[UIImage imageNamed:@"img.png"];

    //Draw your image in that context
    [img drawAtPoint:CGPointMake(50, 50)];

    // pop context
    UIGraphicsPopContext();



     UIImage *image_ = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    //Get that image
    imgvwImage.image=image_;
}

关于ios - 在另一个 uiimage 之上创建图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23057680/

相关文章:

iphone - 如何在文档目录中创建 plist 的精确副本

iphone - iOS中很长的UIScrollView的内存消耗

ios - 从 Firebase 数据库读取数据时出现问题

iphone - UITableViewCell 为 Nil

ios - UILabel 获取底部空间约束 - 自动布局

iphone - NavigationBar setShadowImage 并不总是有效

ios - 游戏中的SpriteKit Shop场景

ios - Swift - 带有 UIPickerView 完成按钮的 UIToolbar 在横向上消失

iphone - 检测选定的 map 注释 Xcode

iphone - 如何在此线程中间更新 UI?