如何在iphone中绘图后在一个图像视图中保存两个图像视图

时间:2013-01-21 07:56:57

标签: iphone objective-c cocoa-touch ios5 ios6

**我有两个图像视图,一个用于背景,一个用于前景,我正在绘制前景imageview.for擦除功能我这样做是因为我不想在擦除时擦除背景图像。 fine.now我想保存那个图像(背景+前景),我需要通过mail.it来实现这个目标。 **

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    if (doodlemode==YES){

    UITouch *touch = [touches anyObject];

    previousPoint2 = previousPoint1;
    previousPoint1 = [touch previousLocationInView:self.view];
    currentPoint = [touch locationInView:self.view];


    // calculate mid point
    CGPoint mid1 = midPoint(previousPoint1, previousPoint2);
    CGPoint mid2 = midPoint(currentPoint, previousPoint1);

    UIGraphicsBeginImageContext(imageDoodle.frame.size);

    CGContextRef context = UIGraphicsGetCurrentContext();


     [imgView.image drawInRect:CGRectMake(0, 0, imageDoodle.frame.size.width,      

     imageDoodle.frame.size.height)];

    CGContextMoveToPoint(context, mid1.x, mid1.y);

    CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);

    CGContextSetLineCap(context, kCGLineCapRound);

    [imgView.layer renderInContext:UIGraphicsGetCurrentContext()];

    //this is for erase
    if(IsErase)
    {
    CGContextSetBlendMode(context,kCGBlendModeClear);
    }
    //make a strok color
    else
    {
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redvalue, greenvalue, bluevalue,  

    1.0);
    }

    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 8.0);
    //size of stroke

    CGContextStrokePath(UIGraphicsGetCurrentContext());


    imgView.image = UIGraphicsGetImageFromCurrentImageContext();


     UIGraphicsEndImageContext();

    }

 }
   -(IBAction)sharePrint{
    //Compose email with activity sheet attached

     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

     picker.mailComposeDelegate = self;

    [UIImage imageNamed:@"feedback.png"]]];

    *//here i nedd to sand that. Image  how can i?*

     NSData *imageData = UIImagePNGRepresentation(imgView.image);

    [picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"shared.png"];

     //Show Mail view with composed email

    [self presentModalViewController:picker animated:YES];

     }

2 个答案:

答案 0 :(得分:2)


- (void) someMethod {
    UIImage *newImage = [self captureScreen];
    IBbtn1.hidden = FALSE;
    IBbtn2.hidden = FALSE;
}

- (UIImage *) captureScreen { 

    IBbtn1.hidden = TRUE;
    IBbtn2.hidden = TRUE;

    CGRect rect = [wrapperView bounds]; 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    [wrapperView.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return img; 
}

答案 1 :(得分:0)

您可以捕捉具有背景和前景图像的视图,并将其存储为sinalge图像,并可以邮寄捕获的图像。