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