合成圖片的兩種方法,思路都是一樣的

theFeng-發表於2014-10-17

- (void)viewDidLoad {

    [super viewDidLoad];

CGRect frame= CGRectMake(520280320480);

CGImageRef small;

small= CGImageCreateWithImageInRect([[UIImage imageNamed:@"3.png"CGImage],frame);

UIImageView *test=[[UIImageView allocinitWithImage:[UIImage imageWithCGImage:small]];

[self.view addSubview:test];

[test release];

}

合成圖片的兩種方法,思路都是一樣的

// ImageImage ICON

- (UIImage *)addImage:(UIImageView *)image1 toImage:(UIImageView *)image2 {

CGSize size= CGSizeMake( image1.frame.size.width,image1.frame.size.height);

UIGraphicsBeginImageContext(size);

    

    // Draw image1

[image2.image drawInRect:CGRectMake(66, image2.frame.size.width, image2.frame.size.height)];

    

// Draw image2    

[image1.image drawInRect:CGRectMake(00, image1.frame.size.width, image1.frame.size.height)];

    

UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    

UIGraphicsEndImageContext();

    

return resultingImage;

}


- (UIImage *)addImageview:(UIImage *)image1 toImage:(UIImage *)image2 {

CGSize size= CGSizeMake( image1.size.width,image1.size.height);

UIGraphicsBeginImageContext(size);

    

    // Draw image1

[image2 drawInRect:CGRectMake(4.567777)];

    

// Draw image2    

[image1 drawInRect:CGRectMake(00, image1.size.width, image1.size.height)];

    

UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    

UIGraphicsEndImageContext();

    

return resultingImage;

}


相關文章