2012-08-31 10 views
5

Pracuję nad aplikacją na iPhone'a i chcę połączyć dwie UIImages (leftImage i rightImage). Czy ktoś może zasugerować, jak to zrobić bez linii pomiędzy nimi?Jak scalić dwa obiekty UIImage w Objective-C w iPhone SDK

Jestem obecnie to robi:

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

} 

ale tworzy małą linię między dwoma obrazami. Nie chcę tego separatora, tak jak robi to Splitcam.

Jak mogę to zrobić?

Odpowiedz

6

Po prostu krawędzie zachodzą na siebie o jeden piksel.

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

Nie działa nadal daje między nimi linię. –