2012-09-11 70 views
0

可能重複:
How to merge two images after rotate the image?如何合併旋轉圖像和背景圖片?

我用兩個圖像的前景圖像旋轉,背景圖像是穩定的。如何合併這兩個圖像?它不適合我工作。提前致謝。

UIGraphicsBeginImageContext(itemSize); 
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

你嘗試過什麼?你失敗了嗎?什麼是錯誤?你的代碼是什麼? –

+0

UIGraphicsBeginImageContext(itemSize); 的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();我試過這樣。但旋轉圖像沒有正確合併。 – Mani

+1

請修改您的問題,而不是在評論中發佈大量代碼。謝謝! –

回答

0

這裏imgDisplayImage是UIInageVew的情況下,lastRotation是總旋轉角度

//...code...// 
CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSaveGState(context); 

    CGContextTranslateCTM(context, [self.imgDisplayImage center].x, [self.imgDisplayImage center].y); 
    CGContextRotateCTM(context, lastRotation); 
    CGContextTranslateCTM(context, 
          -self.imgDisplayImage.frame.size.width * [[self.imgDisplayImage layer] anchorPoint].x, 
          -self.imgDisplayImage.frame.size.height * [[self.imgDisplayImage layer] anchorPoint].y); 

     [self.imgDisplayImage.layer renderInContext:context]; 
    CGContextRestoreGState(context); 
    // . . . 
+0

感謝您的幫助。我會嘗試這個。 – Mani