2012-09-13 97 views
0

enter image description here如何在旋轉圖像後合併兩張圖像?

旋轉圖像後如何合併旋轉圖像?我使用下面的代碼,它的工作很好,在圖像旋轉之前。如何解決這個問題。請幫幫我。提前致謝。

CGRect backgroundImageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); 
CGRect foregroundImageRect = CGRectMake(rsImageView.frame.origin.x, rsImageView.frame.origin.y, rsImageView.frame.size.width, rsImageView.frame.size.height); 

[backgroundImageView.image drawInRect:backgroundImageRect]; 
[rsImageView.image drawInRect:foregroundImageRect]; 
overlappedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
+0

Ya.Merge旋轉後的圖像。 – Mani

+0

對不起,我的意思是,圖像合併在設備方向? – akk

+0

不適合定位。它是一個手動旋轉。 – Mani

回答

1

添加這個方法調用此旋轉後:

-(UIImage *)getMergedImage 
{ 
UIImage mergedImage; 
UIGraphicsBeginImageContext(backgroundImageView.frame.size) 
[backgroundImageView.layer renderInContext:UIGraphicsGetCurrentContext];//bacgroundImageView here 
UIImage overLappedImage = [self getOverlappedImage]; 
if(overLappedImage) 
{ 
    //CGRectMake(0,0,rsImageView.frame.width,rsImageView.frame.height) 
    [overLappedImage drawInRect:rsImageView.frame blendMode:kCGBlendModeNormal alpha:0.8];//TopMostImageView here 
} 
mergedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return mergedImage; 
} 

添加這種方法來獲得overlappped圖像。

-(UIImage *)getOverlappedImage 
{ 
    UIImage overlappedImage; 
    UIGraphicsBeginImageContext(rsImageView.frame.size) 
    [rsImageView.layer renderInContext:UIGraphicsGetCurrentContext]; //TopMostImageView here 
    overlappedImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return overlappedImage; 
} 
+0

謝謝。它不爲我開火。請多給點意見。我期待你的想法。 – Mani

+0

謝謝我將使用此代碼。 – Mani

+0

查看編輯的答案 –

0

如果要在設備的方向使用此代碼

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
    toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
    //Your cgrectmake for landscape 
} 
else 
{ 
    //Your cgrectmake for Portrait 
} 
} 
+0

不適用於設備旋轉。它是手動旋轉。 – Mani