Ios 在另一个uiimage上创建映像

Ios 在另一个uiimage上创建映像,ios,objective-c,iphone,ios7,cgcontext,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 = UIG

我无法在另一个图像上绘制图像。以下是我正在使用的代码:

-(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();

}

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

尝试用rect而不是AtPoint绘制橡皮擦图像

[eraser drawInRect:CGRectMake(50, 50, width, height)];

试着用rect而不是AtPoint绘制橡皮擦图像

[eraser drawInRect:CGRectMake(50, 50, width, height)];

试着用rect而不是AtPoint绘制橡皮擦图像

[eraser drawInRect:CGRectMake(50, 50, width, height)];

试着用rect而不是AtPoint绘制橡皮擦图像

[eraser drawInRect:CGRectMake(50, 50, width, height)];

您忘记在上下文中绘制底部图像,因此您正在未初始化(黑色)背景上绘制
橡皮擦
图像。您需要添加一些代码来首先绘制所需的背景图像。

您忘记将底部图像绘制到上下文中,因此您正在未初始化(黑色)背景上绘制
橡皮擦图像。您需要添加一些代码来首先绘制所需的背景图像。

您忘记将底部图像绘制到上下文中,因此您正在未初始化(黑色)背景上绘制
橡皮擦图像。您需要添加一些代码来首先绘制所需的背景图像。

您忘记将底部图像绘制到上下文中,因此您正在未初始化(黑色)背景上绘制
橡皮擦图像。您需要添加一些代码来首先绘制所需的背景图像。

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

-(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_;
}

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

-(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_;
}

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

-(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_;
}

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

-(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_;
}


为什么你要画它,你可以有imageview的权利。。!!你只要看看这个答案。@Stark-当我用相同的代码而不是圆来画图像时,警告就会出现,什么也不会显示
CGContextRestoreGState:无效的上下文0x0
为什么要绘制它,可以将imageview设置为右。。!!你只要看看这个答案。@Stark-当我用相同的代码而不是圆来画图像时,警告就会出现,什么也不会显示
CGContextRestoreGState:无效的上下文0x0
为什么要绘制它,可以将imageview设置为右。。!!你只要看看这个答案。@Stark-当我用相同的代码而不是圆来画图像时,警告就会出现,什么也不会显示
CGContextRestoreGState:无效的上下文0x0
为什么要绘制它,可以将imageview设置为右。。!!你只要看看这个答案。@Stark-当我用相同的代码而不是圆来画图像时,警告就会出现,什么也不会显示
CGContextRestoreGState:无效的上下文0x0
如何绘制所需的背景图像?有几种方法。例如,请参见答案并复制注释//draw original Images下面的4行。如何绘制所需的背景图像?有几种方法。例如,请参见答案并复制注释//draw original Images下面的4行。如何绘制所需的背景图像?有几种方法。例如,请参见答案并复制注释//draw original Images下面的4行。如何绘制所需的背景图像?有几种方法。例如,请在中查看答案,并复制注释//绘制原始图像下方的4行