大图片中截取其中一部分小图显示 两图合成一图[转载]

- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 {     
 UIGraphicsBeginImageContext(image1.size);          // Draw image1          
 [image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];          // Draw image2         
 [image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)];      
 UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();     
 UIGraphicsEndImageContext();            
 return resultingImage; 
}

大图中间截取小图
#define     PhotoWidth                  220 
#define     PhotoHeight                 107  
-(UIImage *)getNewImage:(UIImage *)image {    
 UIImage *tempImage = image;           
 CGImageRef imgRef = tempImage.CGImage;    
 CGRect   rect1 = CGRectMake((tempImage.size.width-PhotoWidth)/2,(tempImage.size.height-PhotoHeight)/2, PhotoWidth, PhotoHeight);     
 CGImageRef img=CGImageCreateWithImageInRect(imgRef,rect1);          
 UIImage *newImage = [UIImage imageWithCGImage:img];     
 CGImageRelease(img);         
 return newImage; 
 }

你可能感兴趣的:(大图片中截取其中一部分小图显示 两图合成一图[转载])