0
我製作了一款相機應用程序,在該應用程序中,我點擊一張圖像並將其剪切成一半,然後單擊其他圖像並從中剪下另一半。
然後這兩個圖像合併我已成功完成此任務,但問題是合併不順利。如何在ios應用程序中合併兩個半圖像?
兩半之間存在明顯的分離......我想知道如何平滑它?
//------merging the two images------
- (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;
}
感謝
(我接受downvote是健康的批評,但請GV RSN,這樣我可以改進)
纔有可能真正合並這兩個圖像的二進制數據,所以你只需要畫一個像? – Fab1n
兩幅圖像的縱橫比都一樣嗎?用戶是否可以像調整方向一樣調整它? – Pochi
@luis奧斯卡耶可以做出這樣的假設 – amar