2012-08-31 10 views
5

Estoy desarrollando una aplicación para iPhone, y quiero unir dos UIImages (leftImage y rightImage). ¿Alguien puede sugerir cómo hacerlo sin tener líneas entre ellos?Cómo fusionar dos objetos UIImage en Objective-C en iPhone SDK

actualmente estoy haciendo esto:

- (UIImage*)mergeImage:(UIImage*)first withImage:(UIImage*)second 
{ 
    // get size of the first image 
    CGImageRef firstImageRef = first.CGImage; 
    CGFloat firstWidth = CGImageGetWidth(firstImageRef); 
    CGFloat firstHeight = CGImageGetHeight(firstImageRef); 

    // get size of the second image 
    CGImageRef secondImageRef = second.CGImage; 
    CGFloat secondWidth = CGImageGetWidth(secondImageRef); 
    CGFloat secondHeight = CGImageGetHeight(secondImageRef); 

    // build merged size 
    CGSize mergedSize = CGSizeMake((firstWidth+secondWidth), MAX(firstHeight, secondHeight)); 

    // capture image context ref 
    UIGraphicsBeginImageContext(mergedSize); 

    //Draw images onto the context 
    [first drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)]; 
    //[second drawInRect:CGRectMake(firstWidth, 0, secondWidth, secondHeight)]; 
    [second drawInRect:CGRectMake(firstWidth, 0, secondWidth, secondHeight) blendMode:kCGBlendModeNormal alpha:1.0]; 

    // assign context to new UIImage 
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 

    // end context 
    UIGraphicsEndImageContext(); 

    return newImage; 

} 

sino que crea una pequeña línea entre las dos imágenes. No quiero este separador, al igual que lo hace Splitcam.

¿Cómo puedo hacer esto?

Respuesta

6

Simplemente haga que los bordes se superpongan en un píxel.

[second drawInRect:CGRectMake(firstWidth-1, 0, secondWidth, secondHeight) 
    blendMode:kCGBlendModeNormal alpha:1.0]; 
+0

Su no funciona todavía da una línea entre ellos. –