Code:
- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.Nsarray*imgarray =[ [Nsarray alloc] initwithobjects: [UIImage imagenamed:@"1.jpg"], [UIImage imagenamed:@"2.jpg"], [UIImage imagenamed:@"3.jpg"], [UIImage imagenamed:@"4.jpg"], [UIImage imagenamed:@"5.jpg"], nil]; //the data in Imgpointarray is the x, y coordinates of the picture after the image is composited. Nsarray *imgpointarray =[[Nsarray alloc] Initwithobjects:@"Ten",@"Ten", @" -",@" -", @" -",@" -", @" +",@" +", @" -",@" -", nil]; BOOL suc= [Self mergedimageonmainimage:[uiimage imagenamed:@"1.jpg"] Withimagearray:imgarray Andimagepointarray:imgpointarray]; if(suc = =YES) {NSLog (@"Images successfully mearged & Saved to Album"); } Else{NSLog (@"Images not mearged & Don't Saved to Album"); }}#pragma-mark-functions//multiple pictures to synthesize a picture-(BOOL) Mergedimageonmainimage: (UIImage *) mainimg Withimagearray: (Nsarray *) Imgarray Andimagepointarray: (NSArray *) imgpointarray{Uigraphicsbeginimagecontext (mainimg.size); [Mainimg Drawinrect:cgrectmake (0,0, MainImg.size.width, MainImg.size.height)]; inti =0; for(UIImage *imginchImgarray) {[img Drawinrect:cgrectmake ([[Imgpointarray objectatindex:i] floatvalue], [[IMGP Ointarray objectatindex:i+1] Floatvalue], img.size.width, img.size.height)]; I+=2; } cgimageref newmergeimg=Cgimagecreatewithimageinrect (Uigraphicsgetimagefromcurrentimagecontext (). Cgimage, CGRectMake (0,0, MainImg.size.width, mainImg.size.height)); Uigraphicsendimagecontext (); if(Newmergeimg = =Nil) { returnNO; } Else{uiimagewritetosavedphotosalbum ([UIImage imagewithcgimage:newmergeimg], self, nil, nil); returnYES; }}
Multiple photo synthesis 1 sheets