合成图片

-(UIImage*)convertViewToImage:(UIView*)v

{

//    CGSize s = v.bounds.size;

    

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(360, 360), NO, [UIScreen mainScreen].scale);

//    UIGraphicsBeginImageContext(CGSizeMake(360, 360));


    CGContextRef context = UIGraphicsGetCurrentContext();

    

    [v.layer renderInContext:context];

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    v.layer.contents = nil;

    return image; 

    

}




- (UIImage *)imageByCroppingImage:(UIImage *)image toSize:(CGSize)size

{

    // not equivalent to image.size (which depends on the imageOrientation)!

    double refWidth = CGImageGetWidth(image.CGImage);

    double refHeight = CGImageGetHeight(image.CGImage);

    

    double x = (refWidth - size.width) / 2.0;

    double y = (refHeight - size.height) / 2.0;

    

    CGRect cropRect = CGRectMake(x, y, size.height, size.width);

    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);

    

    UIImage *cropped = [UIImage imageWithCGImage:imageRef scale:0.0 orientation:UIImageOrientationUp];

    CGImageRelease(imageRef);

    

    return cropped;

}


- (IBAction)mergeBackgroundImage:(id)sender {

    

    //type:3

    

    UIImage *waterMark = [UIImage imageNamed:@"restoAdvert_watermark"];

    UIImage *restoImage =self.iRestoBackGroundImageView.iImageView.image;

    restoImage = [self imageByCroppingImage:restoImage toSize:CGSizeMake(restoImage.size.height, restoImage.size.height) ];

    

    CGSize contextSize = CGSizeMake(360, 360);

    

    

    UIGraphicsBeginImageContext(contextSize);

    // Draw image2

    [restoImage drawInRect:CGRectMake(0, 0, contextSize.width, contextSize.height)];

    

    // Draw image1


    [waterMark drawInRect:CGRectMake(0, 0, contextSize.width/3, contextSize.width/3)];

    

    UIImage *nameBg = [UIImage imageNamed:@"restoAdvert_nameBg"];

    [nameBg drawInRect:CGRectMake(0, contextSize.height*4/5, contextSize.width,contextSize.height/5)];

    //uilable

    

    UILabel *label = [[UILabel alloc] init];

    label.text = self.iRestoNameTextView.text;

    label.textAlignment = NSTextAlignmentCenter;

    label.lineBreakMode = NSLineBreakByClipping;

    label.font =[UIFont boldSystemFontOfSize:43];


    label.textColor = [UIColor colorWithRed:143/255.0 green:63/255.0 blue:81/255.0 alpha:1];

    

    [label drawTextInRect:CGRectMake(5, contextSize.height*4/5, contextSize.width-10, contextSize.height/5)];


    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    

    

    UIGraphicsEndImageContext();

    self.iRestoBackGroundImageView.iImageView.image = resultingImage;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值